annotate test/testgl2.c @ 2140:15b4a74cdac1

Merged r3125:3126 from branches/SDL-1.2: yasm/nasm warning fix.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 03 Jul 2007 09:54:27 +0000
parents 8055185ae4ed
children 114a541cfae2
rev   line source
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 #include <stdlib.h>
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 #include <stdio.h>
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 #include <string.h>
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 #include <math.h>
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
6 #include "common.h"
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #ifdef __MACOS__
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 #define HAVE_OPENGL
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #endif
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 #ifdef HAVE_OPENGL
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 #include "SDL_opengl.h"
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 /* Undefine this if you want a flat cube instead of a rainbow cube */
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 #define SHADED_CUBE
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
19 static CommonState *state;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
20 static SDL_GLContext context;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
22 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
23 static void
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
24 quit(int rc)
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 {
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
26 if (context) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
27 SDL_GL_MakeCurrent(0, NULL);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
28 SDL_GL_DeleteContext(context);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
30 CommonQuit(state);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
31 exit(rc);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
34 static void
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
35 Render()
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 {
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
37 static float color[8][3] = {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
38 {1.0, 1.0, 0.0},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
39 {1.0, 0.0, 0.0},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
40 {0.0, 0.0, 0.0},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
41 {0.0, 1.0, 0.0},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
42 {0.0, 1.0, 1.0},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
43 {1.0, 1.0, 1.0},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
44 {1.0, 0.0, 1.0},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
45 {0.0, 0.0, 1.0}
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
46 };
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
47 static float cube[8][3] = {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
48 {0.5, 0.5, -0.5},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
49 {0.5, -0.5, -0.5},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
50 {-0.5, -0.5, -0.5},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
51 {-0.5, 0.5, -0.5},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
52 {-0.5, 0.5, 0.5},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
53 {0.5, 0.5, 0.5},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
54 {0.5, -0.5, 0.5},
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
55 {-0.5, -0.5, 0.5}
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
56 };
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
57
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
58 /* Do our drawing, too. */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
59 glClearColor(0.0, 0.0, 0.0, 1.0);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
60 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
61
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
62 glBegin(GL_QUADS);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
63
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
64 #ifdef SHADED_CUBE
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
65 glColor3fv(color[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
66 glVertex3fv(cube[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
67 glColor3fv(color[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
68 glVertex3fv(cube[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
69 glColor3fv(color[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
70 glVertex3fv(cube[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
71 glColor3fv(color[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
72 glVertex3fv(cube[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
73
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
74 glColor3fv(color[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
75 glVertex3fv(cube[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
76 glColor3fv(color[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
77 glVertex3fv(cube[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
78 glColor3fv(color[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
79 glVertex3fv(cube[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
80 glColor3fv(color[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
81 glVertex3fv(cube[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
82
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
83 glColor3fv(color[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
84 glVertex3fv(cube[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
85 glColor3fv(color[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
86 glVertex3fv(cube[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
87 glColor3fv(color[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
88 glVertex3fv(cube[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
89 glColor3fv(color[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
90 glVertex3fv(cube[1]);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
92 glColor3fv(color[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
93 glVertex3fv(cube[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
94 glColor3fv(color[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
95 glVertex3fv(cube[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
96 glColor3fv(color[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
97 glVertex3fv(cube[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
98 glColor3fv(color[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
99 glVertex3fv(cube[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
100
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
101 glColor3fv(color[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
102 glVertex3fv(cube[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
103 glColor3fv(color[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
104 glVertex3fv(cube[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
105 glColor3fv(color[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
106 glVertex3fv(cube[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
107 glColor3fv(color[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
108 glVertex3fv(cube[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
109
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
110 glColor3fv(color[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
111 glVertex3fv(cube[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
112 glColor3fv(color[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
113 glVertex3fv(cube[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
114 glColor3fv(color[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
115 glVertex3fv(cube[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
116 glColor3fv(color[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
117 glVertex3fv(cube[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
118 #else /* flat cube */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
119 glColor3f(1.0, 0.0, 0.0);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
120 glVertex3fv(cube[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
121 glVertex3fv(cube[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
122 glVertex3fv(cube[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
123 glVertex3fv(cube[3]);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
125 glColor3f(0.0, 1.0, 0.0);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
126 glVertex3fv(cube[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
127 glVertex3fv(cube[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
128 glVertex3fv(cube[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
129 glVertex3fv(cube[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
130
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
131 glColor3f(0.0, 0.0, 1.0);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
132 glVertex3fv(cube[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
133 glVertex3fv(cube[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
134 glVertex3fv(cube[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
135 glVertex3fv(cube[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
136
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
137 glColor3f(0.0, 1.0, 1.0);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
138 glVertex3fv(cube[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
139 glVertex3fv(cube[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
140 glVertex3fv(cube[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
141 glVertex3fv(cube[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
142
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
143 glColor3f(1.0, 1.0, 0.0);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
144 glVertex3fv(cube[5]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
145 glVertex3fv(cube[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
146 glVertex3fv(cube[3]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
147 glVertex3fv(cube[4]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
148
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
149 glColor3f(1.0, 0.0, 1.0);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
150 glVertex3fv(cube[6]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
151 glVertex3fv(cube[1]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
152 glVertex3fv(cube[2]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
153 glVertex3fv(cube[7]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
154 #endif /* SHADED_CUBE */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
155
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
156 glEnd();
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
157
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
158 glMatrixMode(GL_MODELVIEW);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
159 glRotatef(5.0, 1.0, 1.0, 1.0);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 int
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
163 main(int argc, char *argv[])
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 {
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
165 int fsaa, accel;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
166 int value;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
167 int i, done;
1967
01e29c3e9a29 In general, fill in pointers to structures, rather than return them.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
168 SDL_DisplayMode mode;
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
169 SDL_Event event;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
170 Uint32 then, now, frames;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
172 /* Initialize parameters */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
173 fsaa = 0;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
174 accel = 0;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
176 /* Initialize test framework */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
177 state = CommonCreateState(argv, SDL_INIT_VIDEO);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
178 if (!state) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
179 return 1;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
181 for (i = 1; i < argc;) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
182 int consumed;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
184 consumed = CommonArg(state, i);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
185 if (consumed == 0) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
186 if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
187 ++fsaa;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
188 consumed = 1;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
189 } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
190 ++accel;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
191 consumed = 1;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
192 } else {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
193 consumed = -1;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
194 }
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
195 }
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
196 if (consumed < 0) {
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1967
diff changeset
197 fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]\n", argv[0],
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
198 CommonUsage(state));
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
199 quit(1);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
200 }
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
201 i += consumed;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
204 /* Set OpenGL parameters */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
205 state->window_flags |= SDL_WINDOW_OPENGL;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
206 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
207 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
208 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 if (fsaa) {
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 if (accel) {
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
218 if (!CommonInit(state)) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
219 quit(2);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
221
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
222 /* Create OpenGL context */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
223 context = SDL_GL_CreateContext(state->windows[0]);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
224 if (!context) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
225 fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
226 quit(2);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
227 }
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
228 if (SDL_GL_MakeCurrent(state->windows[0], context) < 0) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
229 fprintf(stderr, "SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
230 quit(2);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
231 }
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
232
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
233 if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 SDL_GL_SetSwapInterval(1);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 } else {
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 SDL_GL_SetSwapInterval(0);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
1967
01e29c3e9a29 In general, fill in pointers to structures, rather than return them.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
239 SDL_GetCurrentDisplayMode(&mode);
01e29c3e9a29 In general, fill in pointers to structures, rather than return them.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
240 printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 printf("\n");
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 printf("Vendor : %s\n", glGetString(GL_VENDOR));
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 printf("Renderer : %s\n", glGetString(GL_RENDERER));
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 printf("Version : %s\n", glGetString(GL_VERSION));
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 printf("\n");
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
248 SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
249 printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
250 SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
251 printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
252 SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
253 printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
254 SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
255 printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
256 SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 if (fsaa) {
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
259 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
261 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 value);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 if (accel) {
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1916
diff changeset
266 SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
270 /* Set rendering settings */
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 glMatrixMode(GL_PROJECTION);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 glLoadIdentity();
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 glMatrixMode(GL_MODELVIEW);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 glLoadIdentity();
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 glEnable(GL_DEPTH_TEST);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 glDepthFunc(GL_LESS);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 glShadeModel(GL_SMOOTH);
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
280 /* Main render loop */
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 frames = 0;
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
282 then = SDL_GetTicks();
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
283 done = 0;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 while (!done) {
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
285 /* Check for events */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
286 ++frames;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
287 while (SDL_PollEvent(&event)) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
288 CommonEvent(state, &event, &done);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
290 for (i = 0; i < state->num_windows; ++i) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
291 int w, h;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
292 SDL_GL_MakeCurrent(state->windows[i], context);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
293 SDL_GetWindowSize(state->windows[i], &w, &h);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
294 glViewport(0, 0, w, h);
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
295 Render();
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
296 SDL_GL_SwapWindow(state->windows[i]);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
300 /* Print out some timing information */
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
301 now = SDL_GetTicks();
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
302 if (now > then) {
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
303 printf("%2.2f frames per second\n",
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
304 ((double) frames * 1000) / (now - then));
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
306 quit(0);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 #else /* HAVE_OPENGL */
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 int
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 main(int argc, char *argv[])
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 {
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 printf("No OpenGL support on this system\n");
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 return 1;
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 }
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 #endif /* HAVE_OPENGL */