glColorPointer( 3, GL_FLOAT, 0, col );
#include <GL/glut.h> #include <GL/gl.h> #include <GL/glu.h> const GLfloat vx[] = { -1,0,0, 0,1,0, 1,0,0 }; const GLubyte ix[] = { 0 , 1 , 2 }; const GLfloat col[] = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 }; void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0,0,-5); //glColor3f(0,0,1); /* glBegin(GL_TRIANGLES); glVertex3f(-1,0,0); glVertex3f(0, 1,0); glVertex3f( 1,0,0); glEnd(); */ glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState( GL_COLOR_ARRAY ); glVertexPointer(3 , GL_FLOAT , 0 , vx); glColorPointer( 3, GL_FLOAT, 0, col ); glDrawElements(GL_TRIANGLES , 3 , GL_UNSIGNED_BYTE , ix); glutSwapBuffers(); } void onKeyboard(unsigned char key, int x, int y) { switch (key) { case '\033': exit(0); default: break; } } void onMouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: break; case GLUT_MIDDLE_BUTTON: break; case GLUT_RIGHT_BUTTON: break; default: break; } } void onReshape(int width, int height) { if (height==0) height=1; if (width==0) width=1; glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void timer(int value) { glutPostRedisplay(); glutTimerFunc(30 , timer , 0); } void glInit(void) { glClearColor(0.9, 0.9, 0.9, 1.0); glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(750,750); int window = glutCreateWindow(argv[0]); glutDisplayFunc(display); glutReshapeFunc(onReshape); glutMouseFunc(onMouse); glutKeyboardFunc(onKeyboard); glutTimerFunc(50 , timer , 0); glInit(); glutMainLoop(); return 1; }
コメントをかく