#include <GL\glew.h>
#include <GL\freeglut.h>
#define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes))
GLuint ChunkVBO, ColorVBO;
GLint data[] = {
0.0, 0.0, -1.0,
1.0, 0.0, -1.0,
1.0, 1.0, 0.0,
0.0, 1.0, 0.0,
};
GLint color[] = {
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0
};
float z = 0.0;
void init(void)
{
glewInit();
glClearColor(1.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
z += 1.0;
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)
z -= 1.0;
break;
default:
break;
}
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity(); /* clear the matrix */
/* viewing transformation */
gluLookAt(z, 0.0, 5.0, z, 0.0, 0.0, 0.0, 1.0, 0.0);
glVertexPointer(3, GL_INT, 0, data);
glColorPointer(3, GL_INT, 0, color);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glPopMatrix();
glutSwapBuffers();
}
int main (int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
Hi.
Have been struggling with VBO’s trying to display polygons in color. The problem is that it doesn’t work even without VBO.
The polygon is black.
Does anyone know what to do, or have some complete sample code to test whether color pointer at all works on my machine?
TIA