【发布时间】:2009-12-28 07:35:11
【问题描述】:
我正在执行我的 OpenGL 程序,但我碰巧遇到了问题, 你能找到它的问题吗?
它以y轴为中心旋转一个平面
当我使用glOrtho 时它工作正常,但gluPerspective 不是。
gluPerspective 存在一些问题,因为当我将角度更改为 0 时,我只能看到一些东西,但看不到全部。但是当我将其更改为 45 时。屏幕上什么也没有出现,我没有得到关于近值和远值的线索。
#include iostream
#include "Xlib.h"
#include "gl.h"
#include "glu.h"
#include "glut.h"
#include math.h
void setupRC()
{
glClearColor(1,0,0,1);
glColor3f(0,0,0);
}
void timerfunc(int value)
{
glutPostRedisplay();
glutTimerFunc(1, timerfunc ,1);
}
void RenderScene()
{
glColor3f(0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static GLfloat rot = 0.0f,x =0.0f , y=1.0f , z=0.0f;
rot++;
glPushMatrix();
glRotatef(rot,0.0,1.0,0.0);
glBegin(GL_POLYGON);
glVertex3i(1,-1,0);
glVertex3i(1,1,0);
glVertex3i(-1,1,0);
glVertex3i(-1,-1,0);
glVertex3i(1,-1,0);
glEnd();
glPopMatrix();
if (rot == 360)
rot = 0;
glutSwapBuffers();
}
void ChangeSize(GLint w, GLint h)
{
if(h==0)
h = 1;
GLfloat aspectratio = (GLfloat)w/(GLfloat)h;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, aspectratio, 1,1000);
/*if(w <= h)
glOrtho(-100,100,-100/aspectratio, 100/aspectratio, 1,-1);
else
glOrtho(-100*aspectratio, 100*aspectratio , -100,100,1,-1);*/
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc , char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(0,0);
glutCreateWindow("chelsea");
glutTimerFunc(1, timerfunc , 1);
setupRC();
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutMainLoop();
return 0;
}
【问题讨论】:
-
也许创建一个更具描述性的标题?
-
使用完整的单词和标点符号使您的问题更容易阅读,从而更轻松地得到答案。
-
哦。我会看到的。感谢您的反馈
-
stackoverflow 应该检查正确的答案,如果它适合你。
标签: opengl