我的代码中遇到了这个奇怪的错误,它不会让我画任何东西......
void render(void) {
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(4.0);
glPointSize(4.0);
glColor3i(0, 1, 1);
glBegin(GL_POINTS);
glVertex2i(0, 0);
glVertex2i(2, 2);
glVertex2i(3, 3);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv) {
int Largura, Altura;
//width
Largura = (abs(Plano::MinX) * Plano::EspacoPix) + (abs(Plano::MaxX) * Plano::EspacoPix);
//height
Altura = (abs(Plano::MinY) * Plano::EspacoPix) + (abs(Plano::MaxY) * Plano::EspacoPix);
// these are cartesian coordinates,
// at class Plano: enum Dimension {MinY=-50, MaxY=50, MinX=-50, MaxX=50, EspacoPix=5};
glutInit(&argc, argv);
glutInitWindowPosition(-1, -1);
glutInitWindowSize(Largura, Altura);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glClearColor(1, 1, 1, 1);
glutCreateWindow("Graphix");
glMatrixMode(GL_PROJECTION);
//glEnable(GL_POINT_SMOOTH);
//glEnable(GL_LINE_SMOOTH);
gluOrtho2D(Plano::MinX, Plano::MaxX, Plano::MinY, Plano::MaxY); // left, right, bottom, top
glutDisplayFunc(render);
glutIdleFunc(render);
std::cout << "[Dbg] Dimensions: Height=" << Altura << "px Width=" << Largura << "px " << std::endl;
std::cout << "[Dbg] Ortho: Left=" << Plano::MinX << ", Right=" << Plano::MaxX << ", Bottom=" << Plano::MinY << ", Top=" << Plano::MaxY << std::endl;
//glGet with argument GL_COLOR_CLEAR_VALUE
float cores[4] = {-1, -1, -1, -1}; // defaults
glGetFloatv(GL_COLOR_CLEAR_VALUE, cores);
std::cout << "[Dbg] Color Buffer: R=" << cores[0] << " G=" << cores[1] << " B=" << cores[2] << " A=" << cores[3] << std::endl;
glutMainLoop();
return(0);
}
我得到的只是一个黑屏和颜色缓冲区,我认为它是 1、1、1、1 实际上是 0、0、0、0 ......如果我错了,请纠正我,但在屏幕的中心是,因为 gluOrtho2D 调用,x=0,y=0,对吗?正确的?:)