我写了一个代码,但我不知道它哪里出错了。有人可以帮我吗?
我在我的代码中写了一些注释。如果有人可以帮助我,我会很高兴。因为我自己找不到错误。:(
#include <windows.h>
#include <gl/glut.h>
// Function callback that is called to draw
void Desenha(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Clean the window
glClear(GL_COLOR_BUFFER_BIT);
// Shows that the color is red
// R G B
glColor3f(1.0f, 0.0f, 0.0f);
// Draw a square
glBegin(GL_QUADS);
glVertex2i(30,226);
glVertex2i(226,30);
// Shows that the color is blue
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2i(30,226);
glVertex2i(226,30);
glEnd();
// Executes the OpenGL's commands
glFlush();
}
// rendering
void Inicializa (void)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
void AlteraTamanhoJanela(GLsizei w, GLsizei h)
{
// Evita a divisao por zero
if(h == 0) h = 1;
// Especifica as dimensões da Viewport
glViewport(0, 0, w, h);
// Inicializa o sistema de coordenadas
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// (left, right, bottom, top)
if (w <= h)
gluOrtho2D (0.0f, 250.0f, 0.0f, 250.0f*h/w);
else
gluOrtho2D (0.0f, 250.0f*w/h, 0.0f, 250.0f);
}
// Function callback that is called to manage the keyboard tasks
void GerenciaTeclado(unsigned char key, int x, int y)
{
switch (key) {
case 97:
case 'a':// change the actual color to red
glColor3f(1.0f, 0.0f, 0.0f);
break;
case 118:
case 'v':// change de color do blue
glColor3f(0.0f, 0.0f, 1.0f);
break;
case 27:
case 'esc':// close the screen
exit(0);
break;
}
glutPostRedisplay();
}
// Main Program
int main(void)
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(256,256);
glutInitWindowPosition(10,10);
glutCreateWindow("Quadrado");
glutDisplayFunc(Desenha);
glutReshapeFunc(AlteraTamanhoJanela);
Inicializa();
glutMainLoop();
}