I’m a beginner at using OpenGL even though I’ve had some experience in C++.
I’m trying to draw shapes and manipulating them, and the code I was working with was running fine yesterday. However, today I boot up VS and every time I try to run my code the command prompt window says:
“Color Index Mode not supported
Press any key to continue…”
And the window just closes. I have absolutely no idea why this started happening, because I didn’t change a single line of code. I’m not sure what the problem is either. Is it something that I have set up wrong? Because code that I know for a fact was working yesterday has this problem today. Google searches don’t turn up anything, as if nobody else has had this problem and I have no idea what to do. Can anyone help, and possibly explain why this error is coming up?
Thanks in advance!
EDIT: Please let me know if I’m posting in the wrong location, and I apologize if I’m not in the right place.
#include <stdlib.h>
#include "glut.h"
#include <math.h>
const double TWO_PI = 6.2831853;
GLsizei winWidth = 500, winHeight = 500; // Initial display window size
GLuint regHex;
static GLfloat rotTheta = 0.0;
// stores a location
class scrPt {
public:
GLint x, y;
};
static void init (void)
{
scrPt hexVertex;
GLdouble hexTheta;
GLint k;
glClearColor (1.0, 1.0, 1.0, 0.0);
/* Set up a display list for a red regular hexagon
* Vertices for the hexagon are six equally spaced
* points around the circumference of a circle.
*/
regHex = glGenLists(1);
glNewList(regHex, GL_COMPILE);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
for(k = 0; k < 6; k++){
hexTheta = TWO_PI * k / 6;
hexVertex.x = 150 + 100 * cos (hexTheta);
hexVertex.y = 150 + 100 * sin (hexTheta);
glVertex2i (hexVertex.x, hexVertex.y);
}
glEnd();
glEndList();
}
void displayHex (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotTheta, 0.0, 0.0, 1.0);
glCallList(regHex);
glPopMatrix();
glutSwapBuffers();
glFlush();
}
void rotateHex (void)
{
rotTheta += 3.0;
if( rotTheta > 360.0)
rotTheta -= 360.0;
glutPostRedisplay();
}
void winReshapeFcn (GLint newWidth, GLint newHeight)
{
glViewport (0,0, (GLsizei) newWidth, (GLsizei) newHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-320.0, 320.0, -320.0, 320.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
glClear (GL_COLOR_BUFFER_BIT);
}
void mouseFcn(GLint button, GLint action, GLint x, GLint y)
{
switch(button){
case GLUT_MIDDLE_BUTTON: // start the rotation
if(action == GLUT_DOWN)
glutIdleFunc(rotateHex);
break;
case GLUT_RIGHT_BUTTON: // stop the rotation
if(action == GLUT_DOWN)
glutIdleFunc(NULL);
break;
default:
break;
}
}
void main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(150,150);
glutInitWindowSize(winWidth, winHeight);
glutCreateWindow ("Animation Example");
init();
glutDisplayFunc (displayHex);
glutReshapeFunc (winReshapeFcn);
glutMouseFunc (mouseFcn);
glutMainLoop();
}