Mercurial > sdl-ios-xcode
annotate test/testgl2.c @ 4844:c4f5bcaf7572
Switched over to poly-polygon region building and shape-tree traversal for Win32.
author | egottlieb |
---|---|
date | Tue, 10 Aug 2010 15:39:46 -0400 |
parents | 19691cebb866 |
children | 762e40fb8e28 |
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) { |
2328
91e601d9df8b
re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents:
2232
diff
changeset
|
27 /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ |
1915
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 { |
3571
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
165 int fsaa, accel; |
1915
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; |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
171 int status; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
173 /* Initialize parameters */ |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
174 fsaa = 0; |
3571
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
175 accel = -1; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
177 /* Initialize test framework */ |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
178 state = CommonCreateState(argv, SDL_INIT_VIDEO); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
179 if (!state) { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
180 return 1; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 } |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
182 for (i = 1; i < argc;) { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
183 int consumed; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
185 consumed = CommonArg(state, i); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
186 if (consumed == 0) { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
187 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
|
188 ++fsaa; |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
189 consumed = 1; |
3571
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
190 } else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) { |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
191 accel = atoi(argv[i+1]); |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
192 consumed = 2; |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
193 } else { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
194 consumed = -1; |
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 } |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
197 if (consumed < 0) { |
3571
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
198 fprintf(stderr, "Usage: %s %s [--fsaa] [--accel n]\n", argv[0], |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
199 CommonUsage(state)); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
200 quit(1); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
201 } |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
202 i += consumed; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 } |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
205 /* Set OpenGL parameters */ |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
206 state->window_flags |= SDL_WINDOW_OPENGL; |
3408
55541ddf13e3
Support for GL initialization parameters has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
207 state->gl_red_size = 5; |
55541ddf13e3
Support for GL initialization parameters has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
208 state->gl_green_size = 5; |
55541ddf13e3
Support for GL initialization parameters has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
209 state->gl_blue_size = 5; |
55541ddf13e3
Support for GL initialization parameters has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
210 state->gl_depth_size = 16; |
3418 | 211 state->gl_double_buffer = 1; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 if (fsaa) { |
3408
55541ddf13e3
Support for GL initialization parameters has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
213 state->gl_multisamplebuffers = 1; |
55541ddf13e3
Support for GL initialization parameters has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
214 state->gl_multisamplesamples = fsaa; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 } |
3571
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
216 if (accel >= 0) { |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
217 state->gl_accelerated = accel; |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
218 } |
3408
55541ddf13e3
Support for GL initialization parameters has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3139
diff
changeset
|
219 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
220 if (!CommonInit(state)) { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
221 quit(2); |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 } |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
223 |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
224 /* Create OpenGL context */ |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
225 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
|
226 if (!context) { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
227 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
|
228 quit(2); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
229 } |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
230 |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1936
diff
changeset
|
231 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
|
232 SDL_GL_SetSwapInterval(1); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 } else { |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 SDL_GL_SetSwapInterval(0); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 } |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
1967
01e29c3e9a29
In general, fill in pointers to structures, rather than return them.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
237 SDL_GetCurrentDisplayMode(&mode); |
01e29c3e9a29
In general, fill in pointers to structures, rather than return them.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
238 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
|
239 printf("\n"); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 printf("Vendor : %s\n", glGetString(GL_VENDOR)); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 printf("Renderer : %s\n", glGetString(GL_RENDERER)); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 printf("Version : %s\n", glGetString(GL_VERSION)); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 printf("\n"); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 |
3139 | 246 status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
247 if (!status) { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
248 printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
249 } else { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
250 printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
251 } |
3139 | 252 status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
253 if (!status) { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
254 printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
255 } else { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
256 printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
257 } |
3139 | 258 status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
259 if (!status) { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
260 printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
261 } else { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
262 printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
263 } |
3139 | 264 status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
265 if (!status) { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
266 printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
267 } else { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
268 printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
269 } |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 if (fsaa) { |
3139 | 271 status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
272 if (!status) { |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
273 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); |
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
274 } else { |
3139 | 275 printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", |
276 SDL_GetError()); | |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
277 } |
3139 | 278 status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
279 if (!status) { |
3139 | 280 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, |
281 value); | |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
282 } else { |
3139 | 283 printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", |
284 SDL_GetError()); | |
3099
82e60908fab1
Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
2328
diff
changeset
|
285 } |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 } |
3571
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
287 if (accel >= 0) { |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
288 status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
289 if (!status) { |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
290 printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel, |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
291 value); |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
292 } else { |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
293 printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
294 SDL_GetError()); |
19691cebb866
Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents:
3570
diff
changeset
|
295 } |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 } |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
298 /* Set rendering settings */ |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 glMatrixMode(GL_PROJECTION); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 glLoadIdentity(); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 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
|
302 glMatrixMode(GL_MODELVIEW); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 glLoadIdentity(); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 glEnable(GL_DEPTH_TEST); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 glDepthFunc(GL_LESS); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 glShadeModel(GL_SMOOTH); |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
308 /* Main render loop */ |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 frames = 0; |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
310 then = SDL_GetTicks(); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
311 done = 0; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 while (!done) { |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
313 /* Check for events */ |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
314 ++frames; |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
315 while (SDL_PollEvent(&event)) { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
316 CommonEvent(state, &event, &done); |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 } |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
318 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
|
319 int w, h; |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
320 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
|
321 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
|
322 glViewport(0, 0, w, h); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
323 Render(); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
324 SDL_GL_SwapWindow(state->windows[i]); |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 } |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 } |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
328 /* Print out some timing information */ |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
329 now = SDL_GetTicks(); |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
330 if (now > then) { |
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
331 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
|
332 ((double) frames * 1000) / (now - then)); |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 } |
1915
a228436a2404
Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents:
1914
diff
changeset
|
334 quit(0); |
2232 | 335 return 0; |
1914
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 } |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 #else /* HAVE_OPENGL */ |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 int |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 main(int argc, char *argv[]) |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 { |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 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
|
344 return 1; |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 } |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 |
051df511279c
Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 #endif /* HAVE_OPENGL */ |