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

« back to all changes in this revision

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