1/* Basic VBO */ 2 3#include <assert.h> 4#include <string.h> 5#include <stdio.h> 6#include <stdlib.h> 7#include <math.h> 8#include <GL/glew.h> 9#include "glut_wrap.h" 10 11 12struct { 13 GLfloat pos[3]; 14 GLubyte color[4]; 15} verts[] = 16{ 17 { { 0.9, -0.9, 0.0 }, 18 { 0x00, 0x00, 0xff, 0x00 } 19 }, 20 21 { { 0.9, 0.9, 0.0 }, 22 { 0x00, 0xff, 0x00, 0x00 } 23 }, 24 25 { { -0.9, 0.9, 0.0 }, 26 { 0xff, 0x00, 0x00, 0x00 } 27 }, 28 29 { { -0.9, -0.9, 0.0 }, 30 { 0xff, 0xff, 0xff, 0x00 } 31 }, 32}; 33 34static void Init( void ) 35{ 36 GLint errnum; 37 GLuint prognum; 38 39 static const char *prog1 = 40 "!!ARBvp1.0\n" 41 "MOV result.color, vertex.color;\n" 42 "MOV result.position, vertex.position;\n" 43 "END\n"; 44 45 glGenProgramsARB(1, &prognum); 46 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); 47 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, 48 strlen(prog1), (const GLubyte *) prog1); 49 50 assert(glIsProgramARB(prognum)); 51 errnum = glGetError(); 52 printf("glGetError = %d\n", errnum); 53 if (errnum != GL_NO_ERROR) 54 { 55 GLint errorpos; 56 57 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); 58 printf("errorpos: %d\n", errorpos); 59 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); 60 } 61 62 63 glEnableClientState( GL_VERTEX_ARRAY ); 64 glEnableClientState( GL_COLOR_ARRAY ); 65 66 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts[0].pos ); 67 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(verts[0]), verts[0].color ); 68 69} 70 71 72 73static void Display( void ) 74{ 75 glClearColor(0.3, 0.3, 0.3, 1); 76 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 77 78 glEnable(GL_VERTEX_PROGRAM_ARB); 79 80 /* glDrawArrays( GL_TRIANGLES, 0, 3 ); */ 81 glDrawArrays( GL_TRIANGLES, 1, 3 ); 82 83 glFlush(); 84} 85 86 87static void Reshape( int width, int height ) 88{ 89 glViewport( 0, 0, width, height ); 90 glMatrixMode( GL_PROJECTION ); 91 glLoadIdentity(); 92 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 93 glMatrixMode( GL_MODELVIEW ); 94 glLoadIdentity(); 95 /*glTranslatef( 0.0, 0.0, -15.0 );*/ 96} 97 98 99static void Key( unsigned char key, int x, int y ) 100{ 101 (void) x; 102 (void) y; 103 switch (key) { 104 case 27: 105 exit(0); 106 break; 107 } 108 glutPostRedisplay(); 109} 110 111 112 113 114int main( int argc, char *argv[] ) 115{ 116 glutInit( &argc, argv ); 117 glutInitWindowPosition( 0, 0 ); 118 glutInitWindowSize( 250, 250 ); 119 glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); 120 glutCreateWindow(argv[0]); 121 glewInit(); 122 glutReshapeFunc( Reshape ); 123 glutKeyboardFunc( Key ); 124 glutDisplayFunc( Display ); 125 Init(); 126 glutMainLoop(); 127 return 0; 128} 129