Use glad instead of GLEW.
[mesa-demos.git] / src / fp / tri-tex.c
blobf81c4be1867ef64f2f3822175ad0331b4ef75e07
2 #include <assert.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <glad/glad.h>
7 #include "glut_wrap.h"
9 #include "readtex.c"
12 #define TEXTURE_FILE DEMOS_DATA_DIR "girl.rgb"
16 static void Init( void )
18 static const char *modulate2D =
19 "!!ARBfp1.0\n"
20 "TEX result.color, fragment.color, texture[0], 2D; \n"
21 "END"
23 GLuint modulateProg;
24 GLuint Texture;
26 if (!GLAD_GL_ARB_fragment_program) {
27 printf("Error: GL_ARB_fragment_program not supported!\n");
28 exit(1);
30 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
32 /* Setup the fragment program */
33 glGenProgramsARB(1, &modulateProg);
34 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
35 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
36 strlen(modulate2D), (const GLubyte *)modulate2D);
38 printf("glGetError = 0x%x\n", (int) glGetError());
39 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
40 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
41 assert(glIsProgramARB(modulateProg));
43 glEnable(GL_FRAGMENT_PROGRAM_ARB);
45 /* Load texture */
46 glGenTextures(1, &Texture);
47 glBindTexture(GL_TEXTURE_2D, Texture);
48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
50 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
51 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
52 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
53 exit(1);
55 /* XXX this enable shouldn't really be needed!!! */
56 glEnable(GL_TEXTURE_2D);
58 glClearColor(.3, .3, .3, 0);
61 static void Reshape(int width, int height)
64 glViewport(0, 0, (GLint)width, (GLint)height);
66 glMatrixMode(GL_PROJECTION);
67 glLoadIdentity();
68 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
69 glMatrixMode(GL_MODELVIEW);
72 static void Key(unsigned char key, int x, int y)
75 switch (key) {
76 case 27:
77 exit(1);
78 default:
79 break;
82 glutPostRedisplay();
85 static void Draw(void)
87 glClear(GL_COLOR_BUFFER_BIT);
89 glBegin(GL_TRIANGLES);
90 glColor3f(0,0,1);
91 /* glTexCoord2f(1, 0); */
92 glVertex3f( 0.9, -0.9, -30.0);
93 glColor3f(1,0,0);
94 /* glTexCoord2f(1, 1); */
95 glVertex3f( 0.9, 0.9, -30.0);
96 glColor3f(0,1,0);
97 /* glTexCoord2f(0, .5); */
98 glVertex3f(-0.9, 0.0, -30.0);
99 glEnd();
101 glFlush();
105 int main(int argc, char **argv)
107 GLenum type;
109 glutInit(&argc, argv);
113 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
115 type = GLUT_RGB;
116 type |= GLUT_SINGLE;
117 glutInitDisplayMode(type);
119 if (glutCreateWindow("First Tri") == GL_FALSE) {
120 exit(1);
123 gladLoadGL();
125 Init();
127 glutReshapeFunc(Reshape);
128 glutKeyboardFunc(Key);
129 glutDisplayFunc(Draw);
130 glutMainLoop();
131 return 0;