freeglut ERROR: Function <glutCreateWindow> called without first calling 'glutInit'.
Este es el codigo:
- Código: Seleccionar todo
#include <GL>
#include <stdio>
#include <stdlib>
void display(void);
int main(int argc, char *argv[]){
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(20,20);
glutInitWindowSize(500,500);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display(void){
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_TRIANGLES);
/*Dibujamos un triángulo*/
glColor3f(1.0,0.0,0.0);
glVertex3f(0.0,0.8,0.0);
glColor3f(0.0,1.0,0.0);
glVertex3f(-0.6,-0.2,0.0);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.6,-0.2,0.0);
glEnd();
glFlush();
sleep(10);
exit(0);
}
Edito: ya consegui solucionar el problema, solo faltaba en el ejemplo llamar a la funcion glInit al comienzo del programa:
- Código: Seleccionar todo
#include <GL>
#include <stdio>
#include <stdlib>
void display(void);
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(20,20);
glutInitWindowSize(500,500);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display(void){
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_TRIANGLES);
/*Dibujamos un triángulo*/
glColor3f(1.0,0.0,0.0);
glVertex3f(0.0,0.8,0.0);
glColor3f(0.0,1.0,0.0);
glVertex3f(-0.6,-0.2,0.0);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.6,-0.2,0.0);
glEnd();
glFlush();
sleep(10);
exit(0);
}