Hi,
This is my first OpenGL program and it doesn’t work, all I get is black. I can’t figure out why. If anyone out there knows (I’m sure it’s a stupid mistake) piece reply ! Thanks
// Tony’s First Test GL program
// Includes
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef GL_VERSION_1_1
void initPointers(void){
static GLint vertices[] = {20,20,20,
20,20,40,
40,20,40,
40,20,20,
20,40,20,
20,40,40,
40,40,40,
40,40,20};
static GLfloat colors[] = {1.0,0.2,0.2,
0.2,0.2,1.0,
0.8,1.0,0.2,
0.75,0.75,0.75,
0.35,0.35,0.35,
0.5,0.5,0.5};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3,GL_INT,0,vertices);
glColorPointer(3,GL_FLOAT,0,colors);
}
void init(void){
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
initPointers();
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
static GLint allIndices[] = {0,3,7,6,3,2,6,7,
1,0,4,5,2,1,5,6,
4,7,6,5,3,0,1,2};
glDrawElements(GL_QUADS,24,GL_INT,allIndices);
glFlush();
}
void reshape (int w,int h){
glViewport(0, 0,(GLsizei) w,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,(GLdouble)(w/h),1.0,150.0);
}
void keyboard(unsigned char key,int x,int y){
switch (key){
case ‘q’:
exit(0);
break;
}
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(300, 300);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
#else
int main(int argc, char** argv)
{
printf("This program demonstrates a feature which is not in OpenGL Version 1.0.
");
printf("If your implementation of OpenGL Version 1.0 has the right extensions,
");
printf("you may be able to modify this program to make it run.
");
return 0;
}
#endif