opengl 只弹出窗口不显示图像!! 10
有没有大神帮忙。。。。#defineGLUT_DISABLE_ATEXIT_HACK#include<windows.h>#include<GL/GL.H>#includ...
有没有大神帮忙。。。。
#define GLUT_DISABLE_ATEXIT_HACK
#include<windows.h>
#include<GL/GL.H>
#include<GL/glut.h>
#include<GL/GLU.H>
#include<math.h>
#define PI 3.1415926
#define GLfloat float
static int day = 20; //day的变化:从0到359
void myDisplay(void)
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(75,1,1,400000000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,-200000000,200000000,0,0,0,0,0,1);
//?绘制红色的“太阳”
glColor3f(1.0f,0.0f,0.0f);
glutSolidSphere(69600000,20,20);
//?绘制蓝色的“地球”
glColor3f(0.0f,0.0f,1.0f);
glRotatef(day/360.0*360.0,0.0f,0.0f,-1.0f);
glTranslatef(150000000,0.0f,0.0f);
glutSolidSphere(15945000,20,20);
//?绘制黄色的“月亮”
glColor3f(1.0f,1.0f,0.0f);
glRotatef(day/30.0*360.0-day/360.0*360.0,0.0f,0.0f,-1.0f);
glTranslatef(38000000,0.0f,0.0f);
glutSolidSphere(4345000,20,20);
//glDisable(GL_DEPTH_TEST);
glFlush();
}
int main(int argc,char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("universe");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
} 展开
#define GLUT_DISABLE_ATEXIT_HACK
#include<windows.h>
#include<GL/GL.H>
#include<GL/glut.h>
#include<GL/GLU.H>
#include<math.h>
#define PI 3.1415926
#define GLfloat float
static int day = 20; //day的变化:从0到359
void myDisplay(void)
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(75,1,1,400000000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,-200000000,200000000,0,0,0,0,0,1);
//?绘制红色的“太阳”
glColor3f(1.0f,0.0f,0.0f);
glutSolidSphere(69600000,20,20);
//?绘制蓝色的“地球”
glColor3f(0.0f,0.0f,1.0f);
glRotatef(day/360.0*360.0,0.0f,0.0f,-1.0f);
glTranslatef(150000000,0.0f,0.0f);
glutSolidSphere(15945000,20,20);
//?绘制黄色的“月亮”
glColor3f(1.0f,1.0f,0.0f);
glRotatef(day/30.0*360.0-day/360.0*360.0,0.0f,0.0f,-1.0f);
glTranslatef(38000000,0.0f,0.0f);
glutSolidSphere(4345000,20,20);
//glDisable(GL_DEPTH_TEST);
glFlush();
}
int main(int argc,char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("universe");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
} 展开
1个回答
2016-07-21
展开全部
我看了你的程序。
初始化的过程中,
在GLEngine::SetProjection函数中,你使用了
glMatrixMode(GL_PROJECTION);
但是在这个函数返回后,程序并没有执行
glMatrixMode(GL_MODELVIEW);
因此之后所有的操作都是作用在投影矩阵上,当然显示不出来了。
解决办法:
在 GLEngine::SetProjection 函数的最后加上一句:
glMatrixMode(GL_MODELVIEW);
问题就解决啦。
顺便说下,引擎封装的不错,加油!
初始化的过程中,
在GLEngine::SetProjection函数中,你使用了
glMatrixMode(GL_PROJECTION);
但是在这个函数返回后,程序并没有执行
glMatrixMode(GL_MODELVIEW);
因此之后所有的操作都是作用在投影矩阵上,当然显示不出来了。
解决办法:
在 GLEngine::SetProjection 函数的最后加上一句:
glMatrixMode(GL_MODELVIEW);
问题就解决啦。
顺便说下,引擎封装的不错,加油!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询