annotate test/testgl.c @ 233:5b42a7f5fab3

SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
author Sam Lantinga <slouken@libsdl.org>
date Tue, 06 Nov 2001 00:15:24 +0000
parents 50620ec9c86a
children 1af4be6a73cd
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
3 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4 #include <math.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 #include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 #ifdef HAVE_OPENGL
214
0e5d6dd77bda Added platform independent OpenGL header - SDL_opengl.h
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
9 #include "SDL_opengl.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 #define SHADED_CUBE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
13 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 void HotKey_ToggleFullScreen(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 SDL_Surface *screen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 screen = SDL_GetVideoSurface();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
20 if ( SDL_WM_ToggleFullScreen(screen) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 printf("Toggled fullscreen mode - now %s\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22 (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 printf("Unable to toggle fullscreen mode\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 void HotKey_ToggleGrab(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 SDL_GrabMode mode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 printf("Ctrl-G: toggling input grab!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 if ( mode == SDL_GRAB_ON ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 printf("Grab was on\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 printf("Grab was off\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 mode = SDL_WM_GrabInput(!mode);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 if ( mode == SDL_GRAB_ON ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 printf("Grab is now on\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 printf("Grab is now off\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 void HotKey_Iconify(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 printf("Ctrl-Z: iconifying window!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 SDL_WM_IconifyWindow();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 int HandleEvent(SDL_Event *event)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 int done;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 done = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 switch( event->type ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 case SDL_ACTIVEEVENT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 /* See what happened */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 printf( "app %s ", event->active.gain ? "gained" : "lost" );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 if ( event->active.state & SDL_APPACTIVE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 printf( "active " );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 } else if ( event->active.state & SDL_APPMOUSEFOCUS ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 printf( "mouse " );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 } else if ( event->active.state & SDL_APPINPUTFOCUS ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 printf( "input " );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 printf( "focus\n" );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 case SDL_KEYDOWN:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 if ( event->key.keysym.sym == SDLK_ESCAPE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 done = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 if ( (event->key.keysym.sym == SDLK_g) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 (event->key.keysym.mod & KMOD_CTRL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 HotKey_ToggleGrab();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 if ( (event->key.keysym.sym == SDLK_z) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 (event->key.keysym.mod & KMOD_CTRL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 HotKey_Iconify();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 if ( (event->key.keysym.sym == SDLK_RETURN) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 (event->key.keysym.mod & KMOD_ALT) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 HotKey_ToggleFullScreen();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 printf("key '%s' pressed\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 SDL_GetKeyName(event->key.keysym.sym));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 case SDL_QUIT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 done = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 return(done);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
99 void SDL_GL_Enter2DMode()
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
100 {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
101 SDL_Surface *screen = SDL_GetVideoSurface();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
102
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
103 /* Note, there may be other things you need to change,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
104 depending on how you have your OpenGL state set up.
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
105 */
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
106 glPushAttrib(GL_ENABLE_BIT);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
107 glDisable(GL_DEPTH_TEST);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
108 glDisable(GL_CULL_FACE);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
109 glEnable(GL_TEXTURE_2D);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
110
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
111 glViewport(0, 0, screen->w, screen->h);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
112
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
113 glMatrixMode(GL_PROJECTION);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
114 glPushMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
115 glLoadIdentity();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
116
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
117 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
118
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
119 glMatrixMode(GL_MODELVIEW);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
120 glPushMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
121 glLoadIdentity();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
122
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
123 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
124 }
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
125
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
126 void SDL_GL_Leave2DMode()
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
127 {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
128 glMatrixMode(GL_MODELVIEW);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
129 glPopMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
130
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
131 glMatrixMode(GL_PROJECTION);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
132 glPopMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
133
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
134 glPopAttrib();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
135 }
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
136
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 void DrawSDLLogo(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 static SDL_Surface *image = NULL;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
140 static GLuint texture;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 static int x = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142 static int y = 0;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
143 static int w, h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 static int delta_x = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 static int delta_y = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 static Uint32 last_moved = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 SDL_Rect dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 SDL_Surface *screen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 if ( image == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 SDL_Surface *temp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 temp = SDL_LoadBMP("icon.bmp");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 if ( temp == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 image = SDL_CreateRGBSurface(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 SDL_SWSURFACE,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 temp->w, temp->h,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 32,
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
162 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 0x000000FF,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 0x0000FF00,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 0x00FF0000,
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
166 0xFF000000
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167 #else
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
168 0xFF000000,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
169 0x00FF0000,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
170 0x0000FF00,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
171 0x000000FF
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 if ( image != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 SDL_BlitSurface(temp, NULL, image, NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 SDL_FreeSurface(temp);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 if ( image == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 }
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
181 w = image->w;
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
182 h = image->h;
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
183
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
184 /* Create an OpenGL texture for the image */
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
185 if ( ! USE_DEPRECATED_OPENGLBLIT ) {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
186 glGenTextures(1, &texture);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
187 glBindTexture(GL_TEXTURE_2D, texture);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
188 glTexParameteri(GL_TEXTURE_2D,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
189 GL_TEXTURE_MAG_FILTER,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
190 GL_NEAREST);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
191 glTexParameteri(GL_TEXTURE_2D,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
192 GL_TEXTURE_MIN_FILTER,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
193 GL_NEAREST);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
194 glTexImage2D(GL_TEXTURE_2D,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
195 0,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
196 GL_RGBA,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
197 w, h,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
198 0,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
199 GL_RGBA,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
200 GL_UNSIGNED_BYTE,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
201 image->pixels);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
202 SDL_FreeSurface(image); /* No longer needed */
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
203 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 screen = SDL_GetVideoSurface();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 /* Show the image on the screen */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 dst.x = x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210 dst.y = y;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
211 dst.w = w;
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
212 dst.h = h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 /* Move it around
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 Note that we do not clear the old position. This is because we
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 perform a glClear() which clears the framebuffer and then only
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 update the new area.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 Note that you can also achieve interesting effects by modifying
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 the screen surface alpha channel. It's set to 255 by default..
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 if ( (SDL_GetTicks() - last_moved) > 100 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 x += delta_x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 if ( x < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 x = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 delta_x = -delta_x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 } else
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
227 if ( (x+w) > screen->w ) {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
228 x = screen->w-w;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 delta_x = -delta_x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 y += delta_y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 if ( y < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 y = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 delta_y = -delta_y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 } else
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
236 if ( (y+h) > screen->h ) {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
237 y = screen->h-h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 delta_y = -delta_y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 }
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
240 if ( USE_DEPRECATED_OPENGLBLIT ) {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
241 SDL_BlitSurface(image, NULL, screen, &dst);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
242 } else {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
243 SDL_GL_Enter2DMode();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
244 glBindTexture(GL_TEXTURE_2D, texture);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
245 glBegin(GL_TRIANGLE_STRIP);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
246 glTexCoord2f(0.0, 0.0); glVertex2i(x, y );
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
247 glTexCoord2f(1.0, 0.0); glVertex2i(x+w, y );
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
248 glTexCoord2f(0.0, 1.0); glVertex2i(x, y+h);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
249 glTexCoord2f(1.0, 1.0); glVertex2i(x+w, y+h);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
250 glEnd();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
251 SDL_GL_Leave2DMode();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
252 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 }
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
254 if ( USE_DEPRECATED_OPENGLBLIT ) {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
255 SDL_UpdateRects(screen, 1, &dst);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
256 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 int RunGLTest( int argc, char* argv[],
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260 int logo, int slowly, int bpp, float gamma )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
262 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263 int rgb_size[3];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 int w = 640;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 int h = 480;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 int done = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 int frames;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 Uint32 start_time, this_time;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 float color[8][3]= {{ 1.0, 1.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270 { 1.0, 0.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
271 { 0.0, 0.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 { 0.0, 1.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 { 0.0, 1.0, 1.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 { 1.0, 1.0, 1.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 { 1.0, 0.0, 1.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 { 0.0, 0.0, 1.0}};
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 float cube[8][3]= {{ 0.5, 0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 { 0.5, -0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 {-0.5, -0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 {-0.5, 0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 {-0.5, 0.5, 0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282 { 0.5, 0.5, 0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 { 0.5, -0.5, 0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 {-0.5, -0.5, 0.5}};
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 Uint32 video_flags;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 int value;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
288 if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 exit( 1 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
291 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 /* See if we should detect the display depth */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 if ( bpp == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295 if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 bpp = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 bpp = 16; /* More doesn't seem to work */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302 /* Set the flags we want to use for setting the video mode */
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
303 if ( logo && USE_DEPRECATED_OPENGLBLIT ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 video_flags = SDL_OPENGLBLIT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306 video_flags = SDL_OPENGL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 for ( i=1; argv[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 if ( strcmp(argv[1], "-fullscreen") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 video_flags |= SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 /* Initialize the display */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 switch (bpp) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 case 8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 rgb_size[0] = 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 rgb_size[1] = 3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 rgb_size[2] = 3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 case 15:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 case 16:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 rgb_size[0] = 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 rgb_size[1] = 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 rgb_size[2] = 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 rgb_size[0] = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 rgb_size[1] = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 rgb_size[2] = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 SDL_Quit();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 exit(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 printf("\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 printf( "Vendor : %s\n", glGetString( GL_VENDOR ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 printf( "Renderer : %s\n", glGetString( GL_RENDERER ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 printf( "Version : %s\n", glGetString( GL_VERSION ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 printf("\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 /* Set the window manager title bar */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364 SDL_WM_SetCaption( "SDL GL test", "testgl" );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 /* Set the gamma for the window */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 if ( gamma != 0.0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 SDL_SetGamma(gamma, gamma, gamma);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
370
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 glViewport( 0, 0, w, h );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372 glMatrixMode( GL_PROJECTION );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 glLoadIdentity( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 glMatrixMode( GL_MODELVIEW );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378 glLoadIdentity( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 glEnable(GL_DEPTH_TEST);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 glDepthFunc(GL_LESS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 glShadeModel(GL_SMOOTH);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 /* Loop until done. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 start_time = SDL_GetTicks();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388 frames = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 while( !done ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 GLenum gl_error;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 char* sdl_error;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 SDL_Event event;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 /* Do our drawing, too. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 glClearColor( 0.0, 0.0, 0.0, 1.0 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 glBegin( GL_QUADS );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 #ifdef SHADED_CUBE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 glColor3fv(color[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 glColor3fv(color[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 glColor3fv(color[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 glColor3fv(color[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 glColor3fv(color[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 glColor3fv(color[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414 glColor3fv(color[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416 glColor3fv(color[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
419 glColor3fv(color[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
420 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 glColor3fv(color[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423 glColor3fv(color[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
424 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425 glColor3fv(color[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
427
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428 glColor3fv(color[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
429 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
430 glColor3fv(color[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
431 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
432 glColor3fv(color[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
433 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434 glColor3fv(color[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
435 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
436
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
437 glColor3fv(color[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439 glColor3fv(color[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
440 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
441 glColor3fv(color[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
442 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443 glColor3fv(color[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 glColor3fv(color[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
447 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448 glColor3fv(color[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 glColor3fv(color[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452 glColor3fv(color[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
453 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 #else // flat cube
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 glColor3f(1.0, 0.0, 0.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
458 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
460
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
461 glColor3f(0.0, 1.0, 0.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
462 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
463 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
464 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
466
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
467 glColor3f(0.0, 0.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
468 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
469 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
470 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
471 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
472
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
473 glColor3f(0.0, 1.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
474 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
475 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
476 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
477 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
478
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
479 glColor3f(1.0, 1.0, 0.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
480 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
481 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
482 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
483 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
484
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
485 glColor3f(1.0, 0.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
486 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
487 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
489 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
490 #endif /* SHADED_CUBE */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
491
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
492 glEnd( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
493
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
494 glMatrixMode(GL_MODELVIEW);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
495 glRotatef(5.0, 1.0, 1.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
496
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
497 /* Draw 2D logo onto the 3D display */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
498 if ( logo ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
499 DrawSDLLogo();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
500 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
501
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
502 SDL_GL_SwapBuffers( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
503
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
504 /* Check for error conditions. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
505 gl_error = glGetError( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
507 if( gl_error != GL_NO_ERROR ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
508 fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
509 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
510
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511 sdl_error = SDL_GetError( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
512
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
513 if( sdl_error[0] != '\0' ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
514 fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
515 SDL_ClearError();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
516 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
517
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
518 /* Allow the user to see what's happening */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
519 if ( slowly ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
520 SDL_Delay( 20 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
521 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
522
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
523 /* Check if there's a pending event. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
524 while( SDL_PollEvent( &event ) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
525 done = HandleEvent(&event);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
526 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
527 ++frames;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
528 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
529
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
530 /* Print out the frames per second */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
531 this_time = SDL_GetTicks();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
532 if ( this_time != start_time ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
533 printf("%2.2f FPS\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
534 ((float)frames/(this_time-start_time))*1000.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
535 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
536
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
537 /* Destroy our GL context, etc. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
538 SDL_Quit( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
539 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
540 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
541
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
542 int main(int argc, char *argv[])
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
543 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
544 int i, logo;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
545 int numtests;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
546 int bpp = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
547 int slowly;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
548 float gamma = 0.0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
549
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
550 logo = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
551 slowly = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
552 numtests = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
553 for ( i=1; argv[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
554 if ( strcmp(argv[i], "-twice") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
555 ++numtests;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
556 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
557 if ( strcmp(argv[i], "-logo") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
558 logo = 1;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
559 USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
560 }
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
561 if ( strcmp(argv[i], "-logoblit") == 0 ) {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
562 logo = 1;
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
563 USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
564 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
565 if ( strcmp(argv[i], "-slow") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
566 slowly = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
567 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
568 if ( strcmp(argv[i], "-bpp") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
569 bpp = atoi(argv[++i]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
570 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
571 if ( strcmp(argv[i], "-gamma") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
572 gamma = (float)atof(argv[++i]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
573 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
574 if ( strncmp(argv[i], "-h", 2) == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
575 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
576 "Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n]\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
577 argv[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
578 exit(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
579 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
580 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
581 for ( i=0; i<numtests; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
582 RunGLTest(argc, argv, logo, slowly, bpp, gamma);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
583 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
584 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
585 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
586
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
587 #else /* HAVE_OPENGL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
588
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
589 int main(int argc, char *argv[])
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
590 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
591 printf("No OpenGL support on this system\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
592 return 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
593 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
594
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
595 #endif /* HAVE_OPENGL */