OpenGL,一个旋转的正方体,为什么红色的面没有显示.#include GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},\x09\x09{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},\x09\x09{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};GLfloat c

来源:学生作业帮助网 编辑:作业帮 时间:2024/12/01 08:17:11
OpenGL,一个旋转的正方体,为什么红色的面没有显示.#include GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},\x09\x09{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},\x09\x09{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};GLfloat c
xWmoV+V&Pıs2ML)A&U4N[Ȑ*`l 416*1@0B,NO vR'q^m`'9~91HJ$Y-Vj7ۿտTڷ/Jjŕznc nɏ͵ڭ-QE^ ټjĒPDNPOO3i"FJE/'KͿf*R[o il=^GsvpS%7)aְ0y:KDsr^.$#e>J@˚mb͖%E4]UerBMfߒ,".Ȓ׀1ޜG d JTёö0X ]Ʀ{!2=\OߎK87W#*\1#xӚ@cȤ:n$dH }iH !W"#2$Eɰ+Ph $$ Zα]UDius9E&ގpY>~`BpјkZԎɪ6+ٳe(UXM2`[1g;"5Lb>17O͏K%4ԩ#D1+d2nɲne61^rhCDIa[0N0oN7# ΕT25 g35?8jqeFIMƓ'Sm ^4QkZIY>fIvLקY:k-U*m7 ~Hl@YfgOjceV/fBAlX9sR#"ɜKPͦޏO%:>L 9M2ҷȊօUXH.C%@4 溴;x2N|bq (q RP&EuHDt @ NpcI*JFY3Šh >o7t,〴C&}A gU5|m'i;~Ηɪ/Ê|ɋs9ger3D 4E`p6 ep6HSf,-{T :pŗ`fk_z]8=<"D^H㈎CdpDGq!qDGq!q`t- ((&o^C Q/8 U/8W/o^} ztLEl43B\v:-=&d݃=݃=pAGvg򺙠6u#/c~UafF;f4w`ZZ+ͭڕ먹qzyϪjnf(5%d5;7F㏟k\xS~k7޽ le| Djjܿ\ Oa!ڃmSP0F{u>lBPQz/ ػ* ˂(7Ѻlχs- k6=z

OpenGL,一个旋转的正方体,为什么红色的面没有显示.#include GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},\x09\x09{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},\x09\x09{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};GLfloat c
OpenGL,一个旋转的正方体,为什么红色的面没有显示.
#include
GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},
\x09\x09{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},
\x09\x09{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};
GLfloat colors[][3] = {{1.0,0.0,0.0},{0.0,1.0,1.0},
\x09\x09{1.0,1.0,0.0},{0.0,1.0,0.0},
\x09\x09{0.0,0.0,1.0},{1.0,0.0,1.0}};
int axis;
float theta[3];
void polygon(int a,int b,int c,int d)
{
\x09glBegin(GL_POLYGON);
\x09glVertex3fv(vertices[a]);
\x09glVertex3fv(vertices[b]);
\x09glVertex3fv(vertices[c]);
\x09glVertex3fv(vertices[d]);
\x09glEnd();
}
void colorcube()
{
\x09glColor3fv(colors[0]);
\x09polygon(0,3,2,1);
\x09glColor3fv(colors[1]);
\x09polygon(2,3,7,6);
\x09glColor3fv(colors[2]);
\x09polygon(3,0,4,7);
\x09glColor3fv(colors[3]);
\x09polygon(1,2,6,5);
\x09glColor3fv(colors[4]);
\x09polygon(4,5,6,7);
\x09glColor3fv(colors[5]);
\x09polygon(5,4,0,1);
}
void spinCube()
{
\x09theta[axis] += 1.0;
\x09if (theta[axis] > 360.0) theta[axis] -= 360.0;
\x09glutPostRedisplay();
}
void mouse(int btn,int state,int x,int y)
{
\x09if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)\x09axis = 0;
\x09if (btn == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)axis = 1;
\x09if (btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)\x09axis = 2;
}
void init()
{
\x09//glClearColor(0.0,0.0,0.0,0.0);
\x09//glColor3f(1.0,1.0,1.0);
}
void display(void)
{
\x09glClear(GL_COLOR_BUFFER_BIT);
\x09glMatrixMode(GL_MODELVIEW);
\x09glLoadIdentity();
\x09gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
\x09glLoadIdentity();
\x09glRotatef(theta[0],1.0,0.0,0.0);
\x09glRotatef(theta[1],0.0,1.0,0.0);
\x09glRotatef(theta[2],0.0,0.0,1.0);
\x09colorcube();
\x09glFlush();
\x09glutSwapBuffers();
}
void reshape(int w,int h)
{
\x09glViewport(0,0,w,h);
\x09glMatrixMode(GL_PROJECTION);
\x09glLoadIdentity();
\x09glOrtho(-4.0,4.0,-4.0,4.0,-4.0,4.0);
}
int main(int argc,char **argv)
{
\x09glutInit(&argc,argv);
\x09glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
\x09glutInitWindowSize(400,400);
\x09glutInitWindowPosition(200,200);
\x09glutCreateWindow("OpenGL");
\x09glutDisplayFunc(display);
\x09glutReshapeFunc(reshape);
\x09glutIdleFunc(spinCube);
\x09glutMouseFunc(mouse);
\x09init();
\x09glutMainLoop();
}

OpenGL,一个旋转的正方体,为什么红色的面没有显示.#include GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},\x09\x09{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},\x09\x09{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};GLfloat c
#include "stdafx.h"
#include
#include
GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},
\x05\x05{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},
\x05\x05{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};
GLfloat colors[][3] = {{1.0,0.0,0.0},{0.0,1.0,1.0},
\x05\x05{1.0,1.0,0.0},{0.0,1.0,0.0},
\x05\x05{0.0,0.0,1.0},{1.0,0.0,1.0}};
int axis;
float theta[3];
void polygon(int a,int b,int c,int d)
{
\x05glBegin(GL_POLYGON);
\x05glVertex3fv(vertices[a]);
\x05glVertex3fv(vertices[b]);
\x05glVertex3fv(vertices[c]);
\x05glVertex3fv(vertices[d]);
\x05glEnd();
}
void colorcube()
{
\x05glColor3fv(colors[0]);
\x05polygon(0,3,2,1);
\x05glColor3fv(colors[1]);
\x05polygon(2,3,7,6);
\x05glColor3fv(colors[2]);
\x05polygon(3,0,4,7);
\x05glColor3fv(colors[3]);
\x05polygon(1,2,6,5);
\x05glColor3fv(colors[4]);
\x05polygon(4,5,6,7);
\x05glColor3fv(colors[5]);
\x05polygon(5,4,0,1);
}
void spinCube()
{
\x05theta[axis] += 1.0;
\x05if (theta[axis] > 360.0) theta[axis] -= 360.0;
\x05glutPostRedisplay();
\x05Sleep(90);
}
void mouse(int btn,int state,int x,int y)
{
\x05if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)\x05axis = 0;
\x05if (btn == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)axis = 1;
\x05if (btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)\x05axis = 2;
}
void init()
{
\x05//glClearColor(0.0,0.0,0.0,0.0);
\x05//glColor3f(1.0,1.0,1.0);
}
void display(void)
{
\x05glClear(GL_COLOR_BUFFER_BIT);
\x05glMatrixMode(GL_MODELVIEW);
\x05glLoadIdentity();
\x05gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
\x05glLoadIdentity();
\x05glRotatef(theta[0],1.0,1.0,0.0);
\x05colorcube();
\x05glFlush();
\x05glutSwapBuffers();
}
void reshape(int w,int h)
{
\x05glViewport(0,0,w,h);
\x05glMatrixMode(GL_PROJECTION);
\x05glLoadIdentity();
\x05glOrtho(-4.0,4.0,-4.0,4.0,-4.0,4.0);
}
int main(int argc,char **argv)
{
\x05glutInit(&argc,argv);
\x05glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
\x05glutInitWindowSize(400,400);
\x05glutInitWindowPosition(200,200);
\x05glutCreateWindow("OpenGL");
\x05glutDisplayFunc(display);
\x05glutReshapeFunc(reshape);
\x05glutIdleFunc(spinCube);
\x05glutMouseFunc(mouse);
\x05init();
\x05glutMainLoop();
}
改下旋转轴就 看到啦

你的程序在我的电脑上跑过了,看到立方体的旋转后我觉得应该是display设置的有问题,因为立方体是旋转绕的轴和你的视线是垂直的,你只能看到4个面,两个侧面你永远看不到。void mouse(int btn, int state, int x, int y) { if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN) axis = 0; if (bt...

全部展开

你的程序在我的电脑上跑过了,看到立方体的旋转后我觉得应该是display设置的有问题,因为立方体是旋转绕的轴和你的视线是垂直的,你只能看到4个面,两个侧面你永远看不到。

收起