1 2#include <stdio.h> 3#include <string.h> 4#include <stdlib.h> 5#include <GL/glew.h> 6#include "glut_wrap.h" 7 8 9static void Init( void ) 10{ 11 static const char *modulate2D = 12 "!!ARBfp1.0\n" 13 "MOV result.color, program.local[32]; \n" 14 "END" 15 ; 16 GLuint modulateProg; 17 18 if (!GLEW_ARB_fragment_program) { 19 printf("Error: GL_ARB_fragment_program not supported!\n"); 20 exit(1); 21 } 22 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 23 24 /* Setup the fragment program */ 25 glGenProgramsARB(1, &modulateProg); 26 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg); 27 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, 28 strlen(modulate2D), (const GLubyte *)modulate2D); 29 30 printf("glGetError = 0x%x\n", (int) glGetError()); 31 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n", 32 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); 33 34 glEnable(GL_FRAGMENT_PROGRAM_ARB); 35 36 glClearColor(.3, .3, .3, 0); 37} 38 39static void Reshape(int width, int height) 40{ 41 42 glViewport(0, 0, (GLint)width, (GLint)height); 43 44 glMatrixMode(GL_PROJECTION); 45 glLoadIdentity(); 46 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 47 glMatrixMode(GL_MODELVIEW); 48} 49 50static void Key(unsigned char key, int x, int y) 51{ 52 53 switch (key) { 54 case 27: 55 exit(1); 56 default: 57 break; 58 } 59 60 glutPostRedisplay(); 61} 62 63static void Draw(void) 64{ 65 glClear(GL_COLOR_BUFFER_BIT); 66 glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 32, 0.25, .5, 0.25, 1); 67 68 glBegin(GL_TRIANGLES); 69 glColor3f(0,0,1); 70 glVertex3f( 0.9, -0.9, -30.0); 71 glColor3f(1,0,0); 72 glVertex3f( 0.9, 0.0, -30.0); 73 glColor3f(0,1,0); 74 glVertex3f(-0.9, 0.0, -30.0); 75 glEnd(); 76 77 glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 32, 0.25, 0, 0.25, 1); 78 79 glBegin(GL_TRIANGLES); 80 glColor3f(0,0,1); 81 glVertex3f( 0.9, 0.0, -30.0); 82 glColor3f(1,0,0); 83 glVertex3f( 0.9, 0.9, -30.0); 84 glColor3f(0,1,0); 85 glVertex3f(-0.9, 0.0, -30.0); 86 glEnd(); 87 88 glFlush(); 89} 90 91 92int main(int argc, char **argv) 93{ 94 GLenum type; 95 96 glutInit(&argc, argv); 97 98 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); 99 100 type = GLUT_RGB | GLUT_SINGLE; 101 glutInitDisplayMode(type); 102 103 if (glutCreateWindow("First Tri") == GL_FALSE) { 104 exit(1); 105 } 106 107 glewInit(); 108 109 Init(); 110 111 glutReshapeFunc(Reshape); 112 glutKeyboardFunc(Key); 113 glutDisplayFunc(Draw); 114 glutMainLoop(); 115 return 0; 116} 117