132001f49Smrg 232001f49Smrg#include <stdio.h> 332001f49Smrg#include <string.h> 432001f49Smrg#include <stdlib.h> 532001f49Smrg#include <GL/glew.h> 632001f49Smrg#include "glut_wrap.h" 732001f49Smrg 832001f49Smrg 932001f49Smrgstatic void Init( void ) 1032001f49Smrg{ 1132001f49Smrg static const char *modulate2D = 1232001f49Smrg "!!ARBfp1.0\n" 1332001f49Smrg "MOV result.color, program.local[32]; \n" 1432001f49Smrg "END" 1532001f49Smrg ; 1632001f49Smrg GLuint modulateProg; 1732001f49Smrg 1832001f49Smrg if (!GLEW_ARB_fragment_program) { 1932001f49Smrg printf("Error: GL_ARB_fragment_program not supported!\n"); 2032001f49Smrg exit(1); 2132001f49Smrg } 2232001f49Smrg printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 2332001f49Smrg 2432001f49Smrg /* Setup the fragment program */ 2532001f49Smrg glGenProgramsARB(1, &modulateProg); 2632001f49Smrg glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg); 2732001f49Smrg glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, 2832001f49Smrg strlen(modulate2D), (const GLubyte *)modulate2D); 2932001f49Smrg 3032001f49Smrg printf("glGetError = 0x%x\n", (int) glGetError()); 3132001f49Smrg printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n", 3232001f49Smrg (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); 3332001f49Smrg 3432001f49Smrg glEnable(GL_FRAGMENT_PROGRAM_ARB); 3532001f49Smrg 3632001f49Smrg glClearColor(.3, .3, .3, 0); 3732001f49Smrg} 3832001f49Smrg 3932001f49Smrgstatic void Reshape(int width, int height) 4032001f49Smrg{ 4132001f49Smrg 4232001f49Smrg glViewport(0, 0, (GLint)width, (GLint)height); 4332001f49Smrg 4432001f49Smrg glMatrixMode(GL_PROJECTION); 4532001f49Smrg glLoadIdentity(); 4632001f49Smrg glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 4732001f49Smrg glMatrixMode(GL_MODELVIEW); 4832001f49Smrg} 4932001f49Smrg 5032001f49Smrgstatic void Key(unsigned char key, int x, int y) 5132001f49Smrg{ 5232001f49Smrg 5332001f49Smrg switch (key) { 5432001f49Smrg case 27: 5532001f49Smrg exit(1); 5632001f49Smrg default: 5732001f49Smrg break; 5832001f49Smrg } 5932001f49Smrg 6032001f49Smrg glutPostRedisplay(); 6132001f49Smrg} 6232001f49Smrg 6332001f49Smrgstatic void Draw(void) 6432001f49Smrg{ 6532001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 6632001f49Smrg glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 32, 0.25, .5, 0.25, 1); 6732001f49Smrg 6832001f49Smrg glBegin(GL_TRIANGLES); 6932001f49Smrg glColor3f(0,0,1); 7032001f49Smrg glVertex3f( 0.9, -0.9, -30.0); 7132001f49Smrg glColor3f(1,0,0); 7232001f49Smrg glVertex3f( 0.9, 0.0, -30.0); 7332001f49Smrg glColor3f(0,1,0); 7432001f49Smrg glVertex3f(-0.9, 0.0, -30.0); 7532001f49Smrg glEnd(); 7632001f49Smrg 7732001f49Smrg glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 32, 0.25, 0, 0.25, 1); 7832001f49Smrg 7932001f49Smrg glBegin(GL_TRIANGLES); 8032001f49Smrg glColor3f(0,0,1); 8132001f49Smrg glVertex3f( 0.9, 0.0, -30.0); 8232001f49Smrg glColor3f(1,0,0); 8332001f49Smrg glVertex3f( 0.9, 0.9, -30.0); 8432001f49Smrg glColor3f(0,1,0); 8532001f49Smrg glVertex3f(-0.9, 0.0, -30.0); 8632001f49Smrg glEnd(); 8732001f49Smrg 8832001f49Smrg glFlush(); 8932001f49Smrg} 9032001f49Smrg 9132001f49Smrg 9232001f49Smrgint main(int argc, char **argv) 9332001f49Smrg{ 9432001f49Smrg GLenum type; 9532001f49Smrg 9632001f49Smrg glutInit(&argc, argv); 9732001f49Smrg 9832001f49Smrg glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); 9932001f49Smrg 10032001f49Smrg type = GLUT_RGB | GLUT_SINGLE; 10132001f49Smrg glutInitDisplayMode(type); 10232001f49Smrg 10332001f49Smrg if (glutCreateWindow("First Tri") == GL_FALSE) { 10432001f49Smrg exit(1); 10532001f49Smrg } 10632001f49Smrg 10732001f49Smrg glewInit(); 10832001f49Smrg 10932001f49Smrg Init(); 11032001f49Smrg 11132001f49Smrg glutReshapeFunc(Reshape); 11232001f49Smrg glutKeyboardFunc(Key); 11332001f49Smrg glutDisplayFunc(Draw); 11432001f49Smrg glutMainLoop(); 11532001f49Smrg return 0; 11632001f49Smrg} 117