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      "MUL result.depth.z, fragment.color.z, {.1}.x; \n"
1432001f49Smrg      "MOV result.color, fragment.color.z; \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|GL_DEPTH_BUFFER_BIT);
6732001f49Smrg	glEnable(GL_DEPTH_TEST);
6832001f49Smrg
6932001f49Smrg
7032001f49Smrg    glBegin(GL_TRIANGLES);
7132001f49Smrg    glColor4f(.8,0,.5,0);
7232001f49Smrg	glVertex3f( 0.9, -0.9, -30.0);
7332001f49Smrg	glVertex3f( 0.9,  0.9, -30.0);
7432001f49Smrg	glVertex3f(-0.9,  0.0, -30.0);
7532001f49Smrg
7632001f49Smrg    glColor4f(0,.8,.7,0);
7732001f49Smrg	glVertex3f(-0.9, -0.9, -40.0);
7832001f49Smrg    glColor4f(0,.8,.7,0);
7932001f49Smrg	glVertex3f(-0.9,  0.9, -40.0);
8032001f49Smrg    glColor4f(0,.8,.3,0);
8132001f49Smrg	glVertex3f( 0.9,  0.0, -40.0);
8232001f49Smrg    glEnd();
8332001f49Smrg
8432001f49Smrg    glFlush();
8532001f49Smrg}
8632001f49Smrg
8732001f49Smrg
8832001f49Smrgint main(int argc, char **argv)
8932001f49Smrg{
9032001f49Smrg    glutInit(&argc, argv);
9132001f49Smrg
9232001f49Smrg    glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
9332001f49Smrg
9432001f49Smrg    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE);
9532001f49Smrg
9632001f49Smrg    if (glutCreateWindow("Depth Test") == GL_FALSE) {
9732001f49Smrg	exit(1);
9832001f49Smrg    }
9932001f49Smrg
10032001f49Smrg    glewInit();
10132001f49Smrg
10232001f49Smrg    Init();
10332001f49Smrg
10432001f49Smrg    glutReshapeFunc(Reshape);
10532001f49Smrg    glutKeyboardFunc(Key);
10632001f49Smrg    glutDisplayFunc(Draw);
10732001f49Smrg    glutMainLoop();
10832001f49Smrg	return 0;
10932001f49Smrg}
110