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

« back to all changes in this revision

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