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