palpic2png.c: improve, make usable with ppic binary files
[rofl0r-openDOW.git] / tests / gltest.c
blob1c817c5c187000bff389ceddc815793313555cc4
1 #pragma RcB2 LINK "-lGL"
2 #pragma RcB2 LINK "-lSDL"
3 #include <SDL/SDL_opengl.h>
4 #include <SDL/SDL.h>
5 #include <stdio.h>
6 #include <stdint.h>
7 typedef union {
8 struct colors {
9 uint8_t r,g,b,a;
10 } colors;
11 uint32_t val;
12 } rgba_t;
13 #define RGB(R,G,B) ((rgba_t) {.colors.r = R, .colors.g = G, .colors.b = B, .colors.a = 0xff})
15 #define VMODE_W 320
16 #define VMODE_H 240
17 #define PIC_W 17
18 #define PIC_H 17
20 static rgba_t pic[PIC_H][PIC_W];
21 GLuint texid;
23 void fill() {
24 int x,y;
25 #define COL1 RGB(0x0, 0xff, 0)
26 #define COL2 RGB(0xff, 0xff, 0xff)
27 for(y=0; y<PIC_H; y++) for(x=0;x<PIC_W;x++)
28 if(y == 4 || x == 4) pic[y][x] = COL2;
29 else pic[y][x] = COL1;
31 void draw_shit() {
32 glBindTexture(GL_TEXTURE_2D, texid);
33 glBegin(GL_QUADS);
34 #if 0
35 glTexCoord2f(0,0); glVertex2i(-1,-1);
36 glTexCoord2f(1,0); glVertex2i( 1,-1);
37 glTexCoord2f(1,1); glVertex2i( 1, 1);
38 glTexCoord2f(0,1); glVertex2i(-1, 1);
39 #else
40 glTexCoord2f(0,0); glVertex2i(-1,1);
41 glTexCoord2f(1,0); glVertex2i(1,1);
42 glTexCoord2f(1,1); glVertex2i(1,-1);
43 glTexCoord2f(0,1); glVertex2i(-1, -1);
45 #endif
46 glEnd();
47 SDL_GL_SwapBuffers();
49 void video_init(void) {
50 fill();
51 SDL_Init(SDL_INIT_VIDEO);
52 SDL_Surface *surface = SDL_SetVideoMode(VMODE_W, VMODE_H, 32, SDL_OPENGL);
53 glViewport(0, 0, PIC_W, PIC_H);
54 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
55 glLoadIdentity(); // Reset The Projection Matrix
56 glEnable(GL_TEXTURE_2D);
57 glGenTextures(1, &texid);
58 glBindTexture(GL_TEXTURE_2D, texid);
59 int mode = GL_RGBA;
60 glTexImage2D(GL_TEXTURE_2D, 0, mode, PIC_W, PIC_H, 0, mode, GL_UNSIGNED_BYTE, pic);
61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
63 dprintf(2, "%s\n", glGetString(GL_RENDERER));
65 int main() {
66 video_init();
68 SDL_Event sdl_event;
69 while(1) {
70 while (SDL_PollEvent(&sdl_event)) {
71 switch (sdl_event.type) {
72 case SDL_QUIT:
73 goto dun;
76 draw_shit();
77 SDL_Delay(20);
79 dun:
80 SDL_Quit();