2014-12-02 65 views
-1

能有一个人只提简单的步骤来初始化OpenGL库为Visual Studio。我试过nehe教程,但它不适合我。如何初始化OpenGL库为Visual Studio?

+0

这是我要做的事中的Borland/Embarcadero公司http://stackoverflow.com/a/20679773/2521214所以你需要在MSVC创建类似的应用程序/窗口++和复制功能...忽略任何非GL包括所有杂注...他们是通过VCL为自己的目的而创建,所以你不需要它(也可使用),自动...而不是'Form'使用你的窗口类... – Spektre 2014-12-02 15:01:13

+0

或Google for MSVCpp例如项目...应该有很多有... – Spektre 2014-12-02 15:07:06

回答

0

Open.gl确实在解释Modern OpenGL上下文创建一份好工作。他们甚至把写的实现了几个流行的库有人可能想使用像SFML/SDL/GLFW的时间。

+0

我想知道我可以在Visual Studio 2010 Express Edition的配置对OpenGL的头文件和库。 – 2014-12-03 06:11:04

0

#include <iostream> 
 
#include <conio.h> 
 
#include <windows.h> 
 
#include <gl\GL.h> 
 
#include <gl\GLU.h> 
 
#include <glut.h> 
 

 
using namespace std; 
 
#include <stdlib.h> 
 
static GLfloat spin = 0.0; 
 
void init(void) 
 
{ 
 
glClearColor (0.0, 0.0, 0.0, 0.0); 
 
glShadeModel (GL_FLAT); 
 
} 
 
void display(void) 
 
{ 
 
glClear(GL_COLOR_BUFFER_BIT); 
 
glPushMatrix(); 
 
glRotatef(spin, 0.0, 0.0, 1.0); 
 
glColor3f(1.0, 1.0, 1.0); glRectf(-25.0, -25.0, 25.0, 25.0); 
 
glBegin(GL_LINES); 
 
glColor3f(0.5, 0.5, 0.4); 
 
glVertex3f(0.0,0.0,0.0); 
 
glVertex3f(5.0,10.0,0.0); 
 
glEnd(); 
 
glPopMatrix(); 
 
glutSwapBuffers(); 
 
} 
 
void spinDisplay(void) 
 
{ 
 
spin = spin + 2.0; 
 
if (spin > 360.0) 
 
spin = spin - 360.0; 
 
glutPostRedisplay(); 
 
} 
 
void reshape(int w, int h) 
 
{ 
 
glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
 
glMatrixMode(GL_PROJECTION); 
 
glLoadIdentity(); 
 
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); 
 
glMatrixMode(GL_MODELVIEW); 
 
glLoadIdentity(); 
 
} 
 
void mouse(int button, int state, int x, int y) 
 
{ 
 
switch (button) { 
 
case GLUT_LEFT_BUTTON: 
 
if (state == GLUT_DOWN) 
 
glutIdleFunc(spinDisplay); 
 
break; 
 
case GLUT_MIDDLE_BUTTON: 
 
if (state == GLUT_DOWN) 
 
glutIdleFunc(NULL); 
 
break; 
 
default: 
 
break; 
 
} 
 
} 
 
/* 
 
* Request double buffer display mode. 
 
* Register mouse input callback functions 
 
*/ 
 
int main(int argc, char** argv) 
 
{ 
 
glutInit(&argc, argv); 
 
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); 
 
glutInitWindowSize (250, 250); 
 
glutInitWindowPosition (100, 100); 
 
glutCreateWindow (argv[0]); 
 
init(); 
 
glutDisplayFunc(display); 
 
glutReshapeFunc(reshape); 
 
glutMouseFunc(mouse); 
 
glutMainLoop(); 
 
return 0; 
 
}