利用OpenGL实现三维绘图

flying19 flying19 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#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)

麻烦帮忙改一下,谢谢
...全文

相关推荐

利用OpenGL在MFC中实现三维绘图

视口(Viewport)是OpenGL中用于定义二维渲染空间的一个概念,它将视口坐标映射到窗口坐标。视口设置是渲染流程中的一个关键步骤,它决定了渲染的结果显示在窗口的哪个部分,以及使用怎样的缩放级别。为了渲染茶壶模型,需要定义和编译着色器程序。在这个例子中,一个简单的顶点和片段着色器将用于着色和渲染模型。然后,编译这些着色器并链接为一个着色器程序:// 删除着色器对象。

酸甜草莓二侠

C++实现利用OpenGL实现三维绘图

**错误检查**: - 在开发过程中,使用`glGetError`检查OpenGL调用是否有错误。以上只是C++与OpenGL结合实现三维绘图的基础概念。

Tianttt

学习vc++利用OpenGL实现三维绘图资料.pdf

OpenGL 是一个强大的图形库,由SGI公司推出并被广泛接纳为三维图形开发的标准。它提供了丰富的功能,包括但不限于初始化绘图环境、设置颜色模式、管理光源和材质、定义投影方式以及实现高效的图像渲染。

gy51338424

OpenGL三维坐标系绘图程序

OpenGL三维坐标系绘图程序是计算机图形学领域中的一个经典应用,它利用OpenGL库来创建和展示复杂的3D模型和图像。

zhangxp2006

VC环境下的OpenGL三维图形编程实战

OpenGL(Open Graphics Library)是一个跨语言、跨平台的应用程序编程接口(API),用于渲染2D和3D矢量图形。自1992年由Silicon Graphics公司推出以来,OpenGL已成为图形领域内应用最为广泛的标准之一。它提供了一系列与硬件无关的命令,使得开发者能够创建复杂的视觉效果,而不必关心底层图形硬件的具体实现。首先,需要使用WNDCLASS结构体来定义一个窗口类,其中包含窗口的风格、窗口过程函数、图标、鼠标指针等属性。if (!

虾仁芝麻卷
评论 7
收藏 已收藏
分享
返回顶部
flying19
图形处理/算法 19,463 成员 50,678 内容