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