opengl的测试程序出现的问题

本文档描述了在使用OpenGL编程时遇到的链接错误,具体为多个未解析的外部符号,如 auxMainLoop@4, auxReshapeFunc@4等。通过在源代码中添加#pragma comment(lib, "opengl32.lib"), #pragma comment(lib, "glaux.lib"), #pragma comment(lib, "glu32.lib")来解决这些问题,确保链接到所需的库。" 97632860,8729508,标记永久化技术在可持久化线段树的应用,"['数据结构', '算法', '线段树']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include "windows.h"
//#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
//#include <gl/glaux.h>
#include<GL/gl.h>
#include<GL/glaux.h>
void myinit(void);
void DrawMyObjects(void);
void CALLBACK myReshape(GLsizei w,GLsizei h);
void CALLBACK display(void);


void myinit(void)
{
 glClearColor(0.0,0.0,0.0,0.0);
 glClear(GL_COLOR_BUFFER_BIT);
 glShadeModel(GL_FLAT);
}


void CALLBACK myReshape(GLsizei w,GLsizei h)
{
 glViewport(0,0,w,h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 if(w<=h)
  glOrtho(-20.0,20.0,-20.0*(GLfloat)h/(GLfloat)w, 20.0*(GLfloat)h/(GLfloat)w,-50.0,50.0);
 else
  glOrtho(-20.0*(GLfloat)h/(GLfloat)w, 20.0*(GLfloat)h/(GLfloat)w,-20.0,20.0,-50.0,50.0);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
}

void CALLBACK display(void)
{
 glColor3f(1.0,1.0,0.0);
 DrawMyObjects();
 glFlush();
}

void DrawMyObjects(void)
{
 /* draw some points */
 glBegin(GL_POINTS);
 glColor3f(1.0,0.0,0.0);
 glVertex2f(-10.0,11.0);
 glColor3f(1.0,1.0,0.0);
 glVertex2f(-9.0,10.0);
 glColor3f(0.0,1.0,1.0);
 glVertex2f(-8.0,12.0);
 glEnd();

 /* draw some line_segments */
 glBegin(GL_LINES);
 glColor3f(1.0,1.0,0.0);
 glVertex2f(-11.0,8.0);
 glVertex2f(-7.0,7.0);
 glColor3f(1.0,0.0,1.0);
 glVertex2f(-11.0,9.0);
 glVertex2f(-8.0,6.0);
 glEnd();
 
 
 /* draw one opened_line */
 glBegin(GL_LINE_STRIP);
 glColor3f(0.0,1.0,0.0);
 glVertex2f(-3.0,9.0);
 glVertex2f(2.0,6.0);
 glVertex2f(3.0,8.0);
 glVertex2f(-2.5,6.5);
 glEnd();
 
 
 /* draw one closed_line */
 glBegin(GL_LINE_LOOP);
 glColor3f(0.0,1.0,1.0);
 glVertex2f(7.0,7.0);
 glVertex2f(8.0,8.0);
 glVertex2f(9.0,6.5);
 glVertex2f(10.3,7.5);
 glVertex2f(11.5,6.0);
 glVertex2f(7.5,6.0);
 glEnd();
 
 
 /* draw one filled_polygon */
 glBegin(GL_POLYGON);
 glColor3f(0.5,0.3,0.7);
 glVertex2f(-7.0,2.0);
 glVertex2f(-8.0,3.0);
 glVertex2f(-10.3,0.5);
 glVertex2f(-7.5,-2.0);
 glVertex2f(-6.0,-1.0);
 glEnd();
 
 
 /* draw some filled_quandrangles */
 glBegin(GL_QUADS);
 glColor3f(0.7,0.5,0.2);
 glVertex2f(0.0,2.0);
 glVertex2f(-1.0,3.0);
 glVertex2f(-3.3,0.5);
 glVertex2f(-0.5,-1.0);
 glColor3f(0.5,0.7,0.2);
 glVertex2f(3.0,2.0);
 glVertex2f(2.0,3.0);
 glVertex2f(0.0,0.5);
 glVertex2f(2.5,-1.0);
 glEnd();

 
 /* draw some filled_strip_quandrangles */
 glBegin(GL_QUAD_STRIP);
 glVertex2f(6.0,-2.0);
 glVertex2f(5.5,1.0);
 glVertex2f(8.0,-1.0);
 glColor3f(0.8,0.0,0.0);
 glVertex2f(9.0,2.0);
 glVertex2f(11.0,-2.0);
 glColor3f(0.0,0.0,0.8);
 glVertex2f(11.0,2.0);
 glVertex2f(13.0,-1.0);
 glColor3f(0.0,0.8,0.0);
 glVertex2f(14.0,1.0);
 glEnd();
 
 
 /* draw some filled_triangles */
 glBegin(GL_TRIANGLES);
 glColor3f(0.2,0.5,0.7);
 glVertex2f(-10.0,-5.0);
 glVertex2f(-12.3,-7.5);
 glVertex2f(-8.5,-6.0);
 glColor3f(0.2,0.7,0.5);
 glVertex2f(-8.0,-7.0);
 glVertex2f(-7.0,-4.5);
 glVertex2f(-5.5,-9.0);
 glEnd();
 
 
 /* draw some filled_strip_triangles */
 glBegin(GL_TRIANGLE_STRIP);
 glVertex2f(-1.0,-8.0);
 glVertex2f(-2.5,-5.0);
 glColor3f(0.8,0.8,0.0);
 glVertex2f(1.0,-7.0);
 glColor3f(0.0,0.8,0.8);
 glVertex2f(2.0,-4.0);
 glColor3f(0.8,0.0,0.8);
 glVertex2f(4.0,-6.0);
 glEnd();

 
 // draw some filled_fan_triangles */
 glBegin(GL_TRIANGLE_FAN);
 glVertex2f(8.0,-6.0);
 glVertex2f(10.0,-3.0);
 glColor3f(0.8,0.2,0.5);
 glVertex2f(12.5,-4.5);
 glColor3f(0.2,0.5,0.8);
 glVertex2f(13.0,-7.5);
 glColor3f(0.8,0.5,0.2);
 glVertex2f(10.5,-9.0);
 glEnd();
}


void main(void)
{
 auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
 auxInitPosition(0,0,500,500);
 auxInitWindow("Geometric Primitive Types");
 myinit();
 auxReshapeFunc(myReshape);
 auxMainLoop(display);
}

 

编译出现如下错误:

Linking...
first.obj : error LNK2001: unresolved external symbol _auxMainLoop@4
first.obj : error LNK2001: unresolved external symbol _auxReshapeFunc@4
first.obj : error LNK2001: unresolved external symbol _auxInitWindowA@4
first.obj : error LNK2001: unresolved external symbol _auxInitPosition@16
first.obj : error LNK2001: unresolved external symbol _auxInitDisplayMode@4
Debug/firstopengl.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.

firstopengl.exe - 6 error(s), 0 warning(s)

 

解决方法:在头文件中加入

#pragma comment( lib, "opengl32.lib")

#pragma comment( lib, "glaux.lib")
#pragma comment( lib, "glu32.lib")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值