ups, was missing the -f
[gl-cairo-simple.git] / opengl-rendering.c
blob8ab4258a74452a845838c83a32a8f186cfa6c4bb
1 /*******************************************************************************
2 **3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
3 ** 10 20 30 40 50 60 70 80
4 **
5 ** file:
6 ** opengl-rendering.c
7 **
8 ** author:
9 ** Mirco "MacSlow" Mueller <macslow@bangang.de>
11 ** copyright (C) Mirco Mueller, July 2006, placed under the terms of the LGPL
13 *******************************************************************************/
15 #include <stdio.h>
17 #include "SDL.h"
18 #include "SDL_opengl.h"
19 #include "opengl-rendering.h"
21 /* now this here is _really_ nasty, but I'm too lazy to do it right */
22 #define GL_TEXTURE_RECTANGLE_ARB 0x84F5
24 void
25 init_gl ()
27 printf ("OpenGL version: %s\n", glGetString (GL_VERSION));
28 printf ("OpenGL vendor: %s\n", glGetString (GL_VENDOR));
29 printf ("OpenGL renderer: %s\n", glGetString (GL_RENDERER));
31 glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
32 glDisable (GL_DEPTH_TEST);
33 glEnable (GL_BLEND);
34 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
35 glEnable (GL_TEXTURE_RECTANGLE_ARB);
38 void
39 draw_func (int iWidth,
40 int iHeight,
41 unsigned char* pucSurfaceData,
42 unsigned int uiTextureId)
44 if (!pucSurfaceData)
46 printf ("draw_func() - No valid pointer to surface-data passed\n");
47 return;
50 glMatrixMode (GL_MODELVIEW);
51 glLoadIdentity ();
52 glClear (GL_COLOR_BUFFER_BIT);
54 glPushMatrix ();
56 glBindTexture (GL_TEXTURE_RECTANGLE_ARB, uiTextureId);
57 glTexImage2D (GL_TEXTURE_RECTANGLE_ARB,
59 GL_RGBA,
60 iWidth,
61 iHeight,
63 GL_BGRA,
64 GL_UNSIGNED_BYTE,
65 pucSurfaceData);
67 glColor3f (0.25f, 0.5f, 1.0f);
68 glBegin (GL_QUADS);
69 glTexCoord2f (0.0f, 0.0f);
70 glVertex2f (0.0f, 0.0f);
71 glTexCoord2f ((GLfloat) iWidth, 0.0f);
72 glVertex2f (1.0f, 0.0f);
73 glTexCoord2f ((GLfloat) iWidth, (GLfloat) iHeight);
74 glVertex2f (1.0f, 1.0f);
75 glTexCoord2f (0.0f, (GLfloat) iHeight);
76 glVertex2f (0.0f, 1.0f);
77 glEnd ();
79 glPopMatrix ();
81 SDL_GL_SwapBuffers();
84 void
85 resize_func (int iWidth,
86 int iHeight,
87 unsigned int* puiTextureId)
89 glViewport (0, 0, iWidth, iHeight);
90 glMatrixMode (GL_PROJECTION);
91 glLoadIdentity ();
92 glOrtho (0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
94 glClear (GL_COLOR_BUFFER_BIT);
96 glDeleteTextures (1, puiTextureId);
97 glGenTextures (1, puiTextureId);
98 glBindTexture (GL_TEXTURE_RECTANGLE_ARB, *puiTextureId);
99 glTexImage2D (GL_TEXTURE_RECTANGLE_ARB,
101 GL_RGBA,
102 iWidth,
103 iHeight,
105 GL_BGRA,
106 GL_UNSIGNED_BYTE,
107 NULL);
108 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);