openGL---旋转彩色三角形
#include<windows.h>#include<gl/gl.h>#include<gl/glu.h>#include<gl/glut.h>intscreenWid...
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
int screenWidth = 800;
int screenHeight = 600;
float red = 1.0f;
float green = 1.0f;
float blue = 1.0f;
GLfloat rtri = 100.0f; // 用于三角形的角度
GLfloat rquad = -100.0f; // 用于四边形的角度
void myInit(void)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(red,green,blue);
glViewport(0,0,screenWidth,screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(GLdouble)screenWidth/(GLdouble)screenHeight,0.1,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glRotatef(rquad,1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES); // 绘制三角形
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f); // 上顶点
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f); // 左下
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f); // 右下
glEnd();
glLoadIdentity();
glTranslatef(1.5f,0.0f,-6.0f);
glRotatef(rquad,1.0f,0.0f,0.0f);
glColor3f(0.5f,0.5f,1.0f);
glBegin(GL_QUADS); // 绘制正方形
glVertex3f(-1.0f, 1.0f, 0.0f); // 左上
glVertex3f( 1.0f, 1.0f, 0.0f); // 右上
glVertex3f( 1.0f,-1.0f, 0.0f); // 左下
glVertex3f(-1.0f,-1.0f, 0.0f); // 右下
glEnd();
rtri++;
rquad++;
glutSwapBuffers();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize( screenWidth , screenHeight );
glutInitWindowPosition(100,100);
glutCreateWindow("Nehe");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}
为什么旋转不起,只有一张图。三角形并没有动。。。。。
请告诉我详细原因。 展开
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
int screenWidth = 800;
int screenHeight = 600;
float red = 1.0f;
float green = 1.0f;
float blue = 1.0f;
GLfloat rtri = 100.0f; // 用于三角形的角度
GLfloat rquad = -100.0f; // 用于四边形的角度
void myInit(void)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(red,green,blue);
glViewport(0,0,screenWidth,screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(GLdouble)screenWidth/(GLdouble)screenHeight,0.1,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glRotatef(rquad,1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES); // 绘制三角形
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f); // 上顶点
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f); // 左下
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f); // 右下
glEnd();
glLoadIdentity();
glTranslatef(1.5f,0.0f,-6.0f);
glRotatef(rquad,1.0f,0.0f,0.0f);
glColor3f(0.5f,0.5f,1.0f);
glBegin(GL_QUADS); // 绘制正方形
glVertex3f(-1.0f, 1.0f, 0.0f); // 左上
glVertex3f( 1.0f, 1.0f, 0.0f); // 右上
glVertex3f( 1.0f,-1.0f, 0.0f); // 左下
glVertex3f(-1.0f,-1.0f, 0.0f); // 右下
glEnd();
rtri++;
rquad++;
glutSwapBuffers();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize( screenWidth , screenHeight );
glutInitWindowPosition(100,100);
glutCreateWindow("Nehe");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}
为什么旋转不起,只有一张图。三角形并没有动。。。。。
请告诉我详细原因。 展开
2个回答
江苏贝内克
2024-09-06 广告
2024-09-06 广告
气液旋转接头是一种关键的传输部件,用于江苏贝内克密封科技有限公司的许多产品中。它采用精密的设计和制造,以确保液体和气体在各种应用中的顺畅传输。气液旋转接头具有以下特点:1. 高耐压性:接头能够承受高压力,保证传输的稳定性和流畅性。2. 密封...
点击进入详情页
本回答由江苏贝内克提供
2009-10-24
展开全部
当然不会动了……
glutDisplayFunc(myDisplay);
里的myDisplay只会调用一次啊~当然,如果窗口重绘的话它也会被再次调用~~~
glutDisplayFunc(myDisplay);
里的myDisplay只会调用一次啊~当然,如果窗口重绘的话它也会被再次调用~~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询