利用OpenGL实现三维绘图

flying19 2010-01-05 11:05:36
#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)

麻烦帮忙改一下,谢谢
...全文
277 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jim1024 2010-02-25
  • 打赏
  • 举报
回复
OpenGL学习中。
peterhand07 2010-02-19
  • 打赏
  • 举报
回复
哈哈~~我也遇到这问题
flying19 2010-01-07
  • 打赏
  • 举报
回复
谢谢各位!解决了^-^
flying19 2010-01-07
  • 打赏
  • 举报
回复
谢谢各位!解决了^-^
wuhuwy 2010-01-06
  • 打赏
  • 举报
回复
你需要在Vc编译环境中配置Opengl的开发环境,上网查一下,照着配置就行了。
fandh 2010-01-06
  • 打赏
  • 举报
回复
LNK错误,LNK2001,是你的相关的lib文件没有关联,应该是opengl的lib文件没有关联!你把这3个lib文件的配置到你的工程里面:

opengl32.lib glu32.lib glaux.lib

如果是vc6的话,这样配置:project--settings--link--object/library modules: 里面输入这几个文件名称!
HelloGameProgramer 2010-01-06
  • 打赏
  • 举报
回复
看一下NEHE的教程,在vc 里配置好opengl 就没有问题的了

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧