English 中文(简体)
Cube 开放gl,但混凝土的形象被抽取。
原标题:Cube drawing opengl, but a confused image of cube is drawn
  • 时间:2010-09-27 23:32:38
  •  标签:
  • opengl

Hi I am trying to draw a cube of size 5*5*5 with six diffrent face colors. How ever,I can not see all the faces colored diffrently, all I see is a cube, with confusing colors format. Some faces are clearly visible, while top face , parallel to zx plane is not visible.

预 收

void init(void)
{
glClearColor(0,0,0,0);
glShadeModel(GL_FLAT);
}

void DrawCube(void)
{
glLoadIdentity();
gluLookAt(10, 10, 10, 0, 0, 0, 0, 1, 0);
glBegin(GL_QUADS);

//face in xy plane
glColor3f(0.82, 0.41, 0.12);//this the color with which complete cube is drawn. 
glVertex3f(0,0 ,0 );
glVertex3f(5, 0, 0);
glVertex3f(5, 5, 0);
glVertex3f(0, 5, 0);

//face in yz plane
glColor3f(1, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 5);
glVertex3f(0, 5, 0);
glVertex3f(0, 5, 5);

//face in zx plance
glColor3f(0, 1, 0);
glVertex3f(0, 0, 0  );
glVertex3f(0, 0, 5);
glVertex3f(5, 0, 5);
glVertex3f(5, 0, 0);

//|| to xy plane.
glColor3f(0, 0, 1);
glVertex3f(0, 0, 5);
glVertex3f(5, 0, 5);
glVertex3f(5, 5, 5);
glVertex3f(0, 5, 5);

//|| to yz plane
glColor3f(0.73, 0.58, 0.58);
glVertex3f(0,0 ,5 );
glVertex3f(5, 0, 5);
glVertex3f(5, 5, 5);
glVertex3f(0, 5, 5);

//|| to zx plane //this face is not visible. I am not understanding why.
glVertex3f(0.58, 0, 0.82);
glVertex3f(0, 5, 0  );
glVertex3f(0, 5, 5);
glVertex3f(5, 5, 5);
glVertex3f(5, 5, 0);
glEnd();
glFlush();
}


void reshape(int w,int h){

glViewport(0, 0, (GLsizei)w, (GLsizei)h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 1.5, 20);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv){

glutInit(&argc, argv);//we initizlilze the glut. functions
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(DrawCube);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
最佳回答
//|| to zx plane //this face is not visible. I am not understanding why.
glVertex3f(0.58, 0, 0.82);

页: 1 我对此进行猜测。

两个无关的事项:

  • Your || to xy plane quad is the same as your || to yz plane quad.
  • You aren t clearing the color buffer before drawing. You probably want glClear(GL_COLOR_BUFFER_BIT) at the start of DrawCube
问题回答

暂无回答




相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签