利用OpenGL实现三维绘图
#include "windows.h"
#include "gl/gl.h"
#include "gl/glaux.h"
#include "math.h"
void myinit()
{ glClearColor(1,1,0,0);
GLfloat ambient[]={0.5,0.5,0.5,0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);
GLfloat mat_ambient[]={0.8f,0.8f,0.8f,1.0f};
GLfloat mat_diffuse[]={0.8f,0.0f,0.8f,1.0f};
GLfloat mat_specular[]={1.0f,0.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
GLfloat light_diffuse[]={0,0,0.5,1};
GLfloat light_position[]={0,0,1.0,0};
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
}
void CALLBACK display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
auxSolidSphere(1.0);
glFlush();
auxSwapBuffers();
_sleep(100);
}
void CALLBACK Idledisplay()
{ static double x=-0.1,y=0.0;
static BOOL mark=TRUE;
static double step=0.01;
x+=step;
if(x<=0.1&&x>=-0.1)
{ if(step>0)
y=sqrt(0.01-x*x);
else
y=-sqrt(0.01-x*x);
glTranslated(x,y,0);
}
else
{ step=0-step;
}
display();
}
void CALLBACK myReshape(GLsizei w,GLsizei h)
{ glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-3.5,3.5,-3.5*(GLfloat)w/(GLfloat)h,3.5*(GLfloat)w/(GLfloat)h,-10,10);
else
glOrtho(-3.5*(GLfloat)w/(GLfloat)h,3.5*(GLfloat)w/(GLfloat)h,-3.5,3.5,-10,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void main()
{ auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA);
auxInitPosition(0,0,400,400);
auxInitWindow("circle");
myinit();
auxReshapeFunc(myReshape);
auxIdleFunc(Idledisplay);
auxMainLoop(display);
}
出错提示:Linking...
2.obj : error LNK2001: unresolved external symbol __imp__glDepthFunc@4
2.obj : error LNK2001: unresolved external symbol __imp__glEnable@4
2.obj : error LNK2001: unresolved external symbol __imp__glLightfv@12
2.obj : error LNK2001: unresolved external symbol __imp__glMaterialfv@12
2.obj : error LNK2001: unresolved external symbol __imp__glLightModelfv@8
2.obj : error LNK2001: unresolved external symbol __imp__glClearColor@16
2.obj : error LNK2001: unresolved external symbol _auxSwapBuffers@0
2.obj : error LNK2001: unresolved external symbol __imp__glFlush@0
2.obj : error LNK2001: unresolved external symbol _auxSolidSphere@8
2.obj : error LNK2001: unresolved external symbol __imp__glClear@4
2.obj : error LNK2001: unresolved external symbol __imp__glTranslated@24
2.obj : error LNK2001: unresolved external symbol __imp__glOrtho@48
2.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
2.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
2.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
2.obj : error LNK2001: unresolved external symbol _auxMainLoop@4
2.obj : error LNK2001: unresolved external symbol _auxIdleFunc@4
2.obj : error LNK2001: unresolved external symbol _auxReshapeFunc@4
2.obj : error LNK2001: unresolved external symbol _auxInitWindowA@4
2.obj : error LNK2001: unresolved external symbol _auxInitPosition@16
2.obj : error LNK2001: unresolved external symbol _auxInitDisplayMode@4
Debug/1.exe : fatal error LNK1120: 21 unresolved externals
执行 link.exe 时出错.
1.exe - 1 error(s), 0 warning(s)
麻烦帮忙改一下,谢谢