openGL相关#include // 太阳、地球和月亮// 假设每个月都是30天// 一年12个月,共是360天static int day = 200; // day的变化:从0到359void myDisplay(void){glEnable(GL_DEPTH_TEST);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BI
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 22:31:34
openGL相关#include // 太阳、地球和月亮// 假设每个月都是30天// 一年12个月,共是360天static int day = 200; // day的变化:从0到359void myDisplay(void){glEnable(GL_DEPTH_TEST);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BI
openGL相关
#include
// 太阳、地球和月亮
// 假设每个月都是30天
// 一年12个月,共是360天
static int day = 200; // 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);
glFlush(); glutSwapBuffers();
}
void myIdle(void)
{
/* 新的函数,在空闲时调用,作用是把日期往后移动一天并重新绘制,达到动画效果 */
++day;
if( day >= 360 )
day = 0;
myDisplay();
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // 修改了参数为GLUT_DOUBLE
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("太阳,地球和月亮"); // 改了窗口标题
glutDisplayFunc(&myDisplay);
glutIdleFunc(&myIdle); // 新加入了这句
glutMainLoop();
return 0;
}
为什我的vc6.0运行后屏幕全是黑色的教程上说是太阳月亮和地球的模型
openGL相关#include // 太阳、地球和月亮// 假设每个月都是30天// 一年12个月,共是360天static int day = 200; // day的变化:从0到359void myDisplay(void){glEnable(GL_DEPTH_TEST);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BI
glTranslatef(150000000, 0.0f, 0.0f);//把所有尺寸都除个大数,比如10000000
glutSolidSphere(15945000, 20, 20);
成为这样
glTranslatef(15.0, 0.0f, 0.0f);
glutSolidSphere(1.5945, 20, 20);
就可以画出来了.