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