~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

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