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