~ubuntu-branches/ubuntu/jaunty/mesa/jaunty

« back to all changes in this revision

Viewing changes to progs/fp/tri-depthwrite2.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-01-23 10:20:24 UTC
  • mfrom: (1.2.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20090123102024-1f3kmb3aea7wzk67
Tags: 7.3~rc3-1ubuntu1
* Merge with Debian experimental.
* Drop 102_dont_vblank.patch, since the new drm code in the kernel
  fixes the bugs that it worked around.
* Bump the build-dependency of libdrm to 2.4.4. It's the first version
  with necessary changes to build this.

Show diffs side-by-side

added added

removed removed

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