opengl与vc
在编辑是会出错
原程序为
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#pragma comment(lib,"glaux.lib")
#include <windows.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<GL/glaux.h>
#include<GL/gl.h>
#include<string>
#include<sstream>
#include<assert.h>
static const int QUIT_VALUE(99);
GLuint listID;
static void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.f,0.f,-4.f);
glCallList(listID);
glutSwapBuffers();
assert(glGetError()==GL_NO_ERROR);
}
static void rehsape(int w, int h)
{
glviewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50.,(double)w/(double)h,1.,10);
glMatrixMode(GL_MODEVIEW);
assert(glGetError()==GL_NO_ERROR);
}
static void mainMenuCB(int value)
{
if(value==QUIT_VALUE)
exit(0);
}
static void init()
{
glDisable(GL_DITHER);
std::string ver((const char*) glGetString(GL_VERSION));
assert(!ver.empty() );
std::istringstream verStream(ver);
int major,minor;
char dumySep;
verStream>>major>>dumySep>>minor;
const bool useVertexArrays=((major>=1)&&(minor>=1));
const GLfloat data[]={
-1.f,-1.f,0.f,
1.f,-1.f,0.f,
0.f,1.f,0.f};
if (useVertexArrays)
{
glEnableClientSate(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,data);
}
listID=glGenLists(1);
glNewList(listID,GL_COMPILE);
if(useVertexArrays)
glDrawArrays(GL_TRIANGLES,0,3);
else
{
glBegin(GL_TRIANGLES);
glVertex3fv(&data[0]);
glVertex3fv(&data[3]);
glVertex3fv(&data[6]);
glEnd();
}
glEndList();
assert(glGetError()==GL_NO_ERROR);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
int mainMenu=glutCreatMenu(mianMenuCB);
glutAddMenuEntry("Quit",QUOIT_VALUE);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
int main(int argc , char **argv )
{
glutInit(&argc,argv);
glutDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(300,300);
glutCreateWindow("simple Examlple");
init();
glutMainLoop();
return 0;
}
出现的错误为:
ex.cpp
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(42) : error C2065: 'glviewport' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(48) : error C2065: 'GL_MODEVIEW' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(85) : error C2065: 'glEnableClientSate' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(115) : error C2065: 'reshape' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(117) : error C2065: 'glutCreatMenu' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(117) : error C2065: 'mianMenuCB' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(118) : error C2065: 'QUOIT_VALUE' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\PictureGame\codefans.net\example\ex.cpp(131) : error C2065: 'glutDisplayMode' : undeclared identifier
执行 cl.exe 时出错.
example.exe - 1 error(s), 0 warning(s)
------解决方案--------------------
我现在是在DX,所以你的问题不是很清楚
不过看你那些好像是说没有定义,你到游戏那边看看
[解决办法]
LZ这段代码哪抄的?
glviewport大小写错误,glViewport。
GL_MODEVIEW拼写错误,GL_MODELVIEW。
glEnableClientSate改成glEnableClientState。
reshape变量未定义,而且也不是这样用的。glutReshapeFunc(int width, int height)
glutCreatMenu拼写错误,glutCreateMenu。
mianMenuCB未定义变量,而且似乎LZ英文也不太好啊……
QUOIT_VALUE改成QUIT_VALUE。
[解决办法]
#pragma comment(lib,"opengl32.lib")#pragma comment(lib,"glu32.lib")#pragma comment(lib,"glaux.lib")#include <windows.h>#include<GL/glu.h>#include<GL/glut.h>#include<GL/glaux.h>#include<GL/gl.h>#include<string>#include<sstream>#include<assert.h>static const int QUIT_VALUE(99);GLuint listID;static void display(){ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.f,0.f,-4.f); glCallList(listID); glutSwapBuffers(); assert(glGetError()==GL_NO_ERROR);}static void reshape(int w, int h){ glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50.,(double)w/(double)h,1.,10); glMatrixMode(GL_MODELVIEW); assert(glGetError()==GL_NO_ERROR); }static void mainMenuCB(int value){ if(value==QUIT_VALUE) exit(0); }static void init(){ glDisable(GL_DITHER); std::string ver((const char*) glGetString(GL_VERSION)); assert(!ver.empty() ); std::istringstream verStream(ver); int major,minor; char dumySep; verStream>>major>>dumySep>>minor; const bool useVertexArrays=((major>=1)&&(minor>=1)); const GLfloat data[]={ -1.f,-1.f,0.f, 1.f,-1.f,0.f, 0.f,1.f,0.f}; if (useVertexArrays) { glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,0,data); } listID=glGenLists(1); glNewList(listID,GL_COMPILE); if(useVertexArrays) glDrawArrays(GL_TRIANGLES,0,3); else { glBegin(GL_TRIANGLES); glVertex3fv(&data[0]); glVertex3fv(&data[3]); glVertex3fv(&data[6]); glEnd(); } glEndList(); assert(glGetError()==GL_NO_ERROR); glutDisplayFunc(display); glutReshapeFunc(reshape); int mainMenu=glutCreateMenu(mainMenuCB); glutAddMenuEntry("Quit",QUIT_VALUE); glutAttachMenu(GLUT_RIGHT_BUTTON);}int main(int argc , char **argv ){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(300,300); glutCreateWindow("simple Examlple"); init(); glutMainLoop(); return 0;}