相机视图和照明问题(openGL& GLUT)

时间:2016-09-28 00:25:30

标签: opengl glut light perspectivecamera

enter image description here

我正在尝试使用三个圆环实现底部子窗口,但未能在子窗口中显示任何内容..

子窗口的主要功能:

B

显示功能:

instrument_window = glutCreateSubWindow(main_window, GAP, view_height + 3*GAP, 2*(view_width+GAP), INSTRUMENT_HEIGHT);
glutDisplayFunc(display);
//lighting
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 600, 1200, 1200, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

//glClearColor(0.33,0.33,0.33,0.33);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
//end of lighting

glutMainLoop();

用于绘制功能:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

float width = 2*(GAP+view_width);
float height = INSTRUMENT_HEIGHT;
const float ar = (float) width / (float) height;

//glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(width/4.0, width*3.0/4.0, height*3.0/4.0, height/4.0, 2.0, 100.0);
//gluPerspective (160.0, 2*view_width/INSTRUMENT_HEIGHT, 0.1, 1000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
/*
glMatrixMode(GL_PROJECTION);
// Reset transformations
glLoadIdentity();
gluPerspective (160.0, 2*view_width/INSTRUMENT_HEIGHT, 0.1, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Draw first
draw (view_width+GAP-400, INSTRUMENT_HEIGHT/2);

// Draw second
draw (view_width+GAP-150, INSTRUMENT_HEIGHT/2);

// Draw third
draw (view_width+GAP+100, INSTRUMENT_HEIGHT/2);

非常令人沮丧,因为它只显示任何内容,不知道如何调试。任何提示都非常感谢!!!!

1 个答案:

答案 0 :(得分:0)

说实话,很难从提供的代码示例中回答这个问题。 “显示功能”的一半'从setText(int)注释掉,所以下面没有任何东西会被调用。即使这样,也难以推断出问题,因为这里几乎没有与多个视口相关的代码。由于您正在使用固定管道GL,请查看NeHe,它有一个很好的使用多个视口的教程。

http://nehe.gamedev.net/tutorial/multiple_viewports/20002/

调试是开发人员在解决问题的过程中最重要的工具。学习如何做到这一点是明智的,因为从长远来看它肯定会节省你的时间,你会找到大多数(如果不是全部)编码问题的答案!