annotate test/testdyngles.c @ 3487:24d13328c44a

Eric Wing to Sam, hfutrell This one is quite puzzling. I found a partial workaround, but I don't fully understand the reasons yet. First, the console is complaining about not finding a nib for MainWindow. I tried removing the entry for this in the info.plist, and the message went away, but it didn't really change anything. Second, I stepped through this with the debugger and broke up some lines. It seems that the basic act of calling view = [SDL_uikitopenglview alloc]; or even view = [SDL_uikitview alloc] will crash the program. The debugger messages plus the stack trace make me think it's not finding the SDL_uikitview classes for some reason. But I don't understand why this would be. view = [UIView alloc] will not crash the program. For kicks, I added a new definition of a class called SDL_object which subclasses NSObject in the same files as SDL_uikitopenglview and then call view = [SDL_object alloc]; This does not crash the program. So, then I modified SDL_object to subclass UIView. No crash. Next, I made SDL_object subclass UIView<UITextFieldDelegate> . This crashes. So it is the act of conforming to the UITextFieldDelegate protocol that is crashing things. I don't understand why it would crash on alloc though. I'm guessing either a delegate needs to be set somewhere or one of the required methods needs to be implemented. But in the former case, I would not expect a crash, but a silent message to nil and something else doesn't work. And in the latter case, I would expect a compiler warning and an exception thrown instead of a crash. Anyway, my temporary workaround is to change the interface declaration for SDL_uikitview to look like: #if SDL_IPHONE_KEYBOARD @interface SDL_uikitview : UIView<UITextFieldDelegate> { #else @interface SDL_uikitview : UIView { #endif And then disable the keyboard support in the SDL_config_iphoneos.h file. /* enable iPhone keyboard support */ #define SDL_IPHONE_KEYBOARD 0 -Eric On Nov 23, 2009, at 1:43 AM, Sam Lantinga wrote: > I ran into a blocking startup crash with the Happy demo on iPhone OS 3.1.2 on my new iPhone: > > #0 0x323fea14 in _class_isInitialized > #1 0x323fea68 in _class_initialize > #2 0x32403e92 in prepareForMethodLookup > #3 0x32401244 in lookUpMethod > #4 0x323fea10 in _class_lookupMethodAndLoadCache > #5 0x323fe746 in objc_msgSend_uncached > #6 0x323feb26 in _class_initialize > #7 0x323fea58 in _class_initialize > #8 0x32403e92 in prepareForMethodLookup > #9 0x32401244 in lookUpMethod > #10 0x323fea10 in _class_lookupMethodAndLoadCache > #11 0x323fe746 in objc_msgSend_uncached > #12 0x000554dc in UIKit_GL_CreateContext at SDL_uikitopengles.m:103 > #13 0x0004f89e in SDL_GL_CreateContext at SDL_video.c:3155 > #14 0x000579e8 in GLES_CreateRenderer at SDL_renderer_gles.c:282 > #15 0x0004d7b8 in SDL_CreateRenderer at SDL_video.c:1509 > #16 0x00002bc2 in SDL_main at happy.c:156 > #17 0x000571b2 in -[SDLUIKitDelegate postFinishLaunch] at > SDL_uikitappdelegate.m:77 > #18 0x313f9ef2 in __NSFireDelayedPerform > #19 0x32567bb2 in CFRunLoopRunSpecific > #20 0x3256735c in CFRunLoopRunInMode > #21 0x32912cbe in GSEventRunModal > #22 0x32912d6a in GSEventRun > #23 0x32b6276e in -[UIApplication _run] > #24 0x32b61472 in UIApplicationMain > #25 0x00057088 in main at SDL_uikitappdelegate.m:50 > > Any ideas? > > See ya! > -- > -Sam Lantinga, Founder and President, Galaxy Gameworks LLC
author Sam Lantinga <slouken@libsdl.org>
date Tue, 24 Nov 2009 08:12:32 +0000
parents f4bc25567731
children 1435f8a6425c
rev   line source
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * Small SDL example to demonstrate dynamically loading
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * OpenGL lib and functions
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 * (FYI it was supposed to look like snow in the wind or something...)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * Compile with :
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 * gcc testdyngl.c `sdl-config --libs --cflags` -o testdyngl -DHAVE_OPENGL
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 * You can specify a different OpenGL lib on the command line, i.e. :
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 * ./testdyngl /usr/X11R6/lib/libGL.so.1.2
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 * or
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 * ./testdyngl /usr/lib/libGL.so.1.0.4496
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 #include <stdio.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 #include <stdlib.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 #include "SDL.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #ifdef __IPHONEOS__
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #define HAVE_OPENGLES
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #endif
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #ifdef HAVE_OPENGLES
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "SDL_opengles.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 static void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 quit(int rc)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 SDL_Quit();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 exit(rc);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 void *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 get_funcaddr(const char *p)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 void *f = SDL_GL_GetProcAddress(p);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 if (f) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 return f;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 } else {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 printf("Unable to get function pointer for %s\n", p);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 quit(1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 return NULL;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 typedef struct
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 void (APIENTRY * glEnableClientState) (GLenum array);
3410
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
54 void (APIENTRY * glDisableClientState) (GLenum array);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 void (APIENTRY * glVertexPointer) (GLint size, GLenum type,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 GLsizei stride,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 const GLvoid * pointer);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 void (APIENTRY * glDrawArrays) (GLenum mode, GLint first, GLsizei count);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 void (APIENTRY * glClearColor) (GLfloat, GLfloat, GLfloat, GLfloat);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 void (APIENTRY * glClear) (GLbitfield);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 void (APIENTRY * glDisable) (GLenum);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 void (APIENTRY * glEnable) (GLenum);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3087
diff changeset
65 void (APIENTRY * glColor4f) (GLfloat, GLfloat, GLfloat, GLfloat);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 void (APIENTRY * glPointSize) (GLfloat);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 void (APIENTRY * glHint) (GLenum, GLenum);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 void (APIENTRY * glBlendFunc) (GLenum, GLenum);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 void (APIENTRY * glMatrixMode) (GLenum);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 void (APIENTRY * glLoadIdentity) ();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 void (APIENTRY * glOrthof) (GLfloat, GLfloat, GLfloat, GLfloat,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 GLfloat, GLfloat);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 void (APIENTRY * glRotatef) (GLfloat, GLfloat, GLfloat, GLfloat);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 void (APIENTRY * glViewport) (GLint, GLint, GLsizei, GLsizei);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 void (APIENTRY * glFogf) (GLenum, GLfloat);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 glfuncs;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 init_glfuncs(glfuncs * f)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 f->glEnableClientState = get_funcaddr("glEnableClientState");
3410
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
83 f->glDisableClientState = get_funcaddr("glDisableClientState");
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 f->glVertexPointer = get_funcaddr("glVertexPointer");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 f->glDrawArrays = get_funcaddr("glDrawArrays");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 f->glClearColor = get_funcaddr("glClearColor");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 f->glClear = get_funcaddr("glClear");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 f->glDisable = get_funcaddr("glDisable");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 f->glEnable = get_funcaddr("glEnable");
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3087
diff changeset
90 f->glColor4f = get_funcaddr("glColor4f");
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 f->glPointSize = get_funcaddr("glPointSize");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 f->glHint = get_funcaddr("glHint");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 f->glBlendFunc = get_funcaddr("glBlendFunc");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 f->glMatrixMode = get_funcaddr("glMatrixMode");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 f->glLoadIdentity = get_funcaddr("glLoadIdentity");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 f->glOrthof = get_funcaddr("glOrthof");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 f->glRotatef = get_funcaddr("glRotatef");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 f->glViewport = get_funcaddr("glViewport");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 f->glFogf = get_funcaddr("glFogf");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 #define NB_PIXELS 1000
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 main(int argc, char *argv[])
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 glfuncs f;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 int i;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 SDL_Event event;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 int done = 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 GLfloat pixels[NB_PIXELS * 3];
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 const char *gl_library = NULL; /* Use the default GL library */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 int video_w, video_h;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 /* you may want to change these according to the platform */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 video_w = 320;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 video_h = 480;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
119 #ifdef __QNXNTO__
3410
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
120 video_w = 480;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
121 video_h = 640;
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
122 #endif /* __QNXNTO__ */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 if (argv[1]) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 gl_library = argv[1];
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 printf("Unable to init SDL : %s\n", SDL_GetError());
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 return (1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 if (SDL_GL_LoadLibrary(gl_library) < 0) {
3087
0b6f51c29267 Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
134 printf("Unable to dynamically open GL ES lib : %s\n", SDL_GetError());
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 quit(1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 if (SDL_SetVideoMode(video_h, video_w, 0, SDL_OPENGL) == NULL) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 printf("Unable to open video mode : %s\n", SDL_GetError());
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 quit(1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 /* Set the window manager title bar */
3087
0b6f51c29267 Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
144 SDL_WM_SetCaption("SDL Dynamic OpenGL ES Loading Test", "testdyngles");
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 init_glfuncs(&f);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 for (i = 0; i < NB_PIXELS; i++) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 pixels[3 * i] = rand() % 250 - 125;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 pixels[3 * i + 1] = rand() % 250 - 125;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 pixels[3 * i + 2] = rand() % 250 - 125;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
154 #ifdef __QNXNTO__
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
155 f.glViewport(0, 0, video_h, video_w);
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
156 #else
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
157 f.glViewport(0, 0, video_w, video_h);
Sam Lantinga <slouken@libsdl.org>
parents: 3099
diff changeset
158 #endif /* __QNXNTO__ */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 f.glMatrixMode(GL_PROJECTION);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 f.glLoadIdentity();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 f.glOrthof(-100, 100, -100, 100, -500, 500);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 f.glMatrixMode(GL_MODELVIEW);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 f.glLoadIdentity();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 f.glEnable(GL_DEPTH_TEST);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 f.glDisable(GL_TEXTURE_2D);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 f.glEnable(GL_BLEND);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 f.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 f.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 f.glEnable(GL_POINT_SMOOTH);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 f.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
3410
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
177 f.glPointSize(1.0f);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 f.glEnable(GL_FOG);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 f.glFogf(GL_FOG_START, -500);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 f.glFogf(GL_FOG_END, 500);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 f.glFogf(GL_FOG_DENSITY, 0.005);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
3410
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
183 f.glVertexPointer(3, GL_FLOAT, 0, pixels);
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
184 f.glEnableClientState(GL_VERTEX_ARRAY);
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
185
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 do {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 f.glRotatef(2.0, 1.0, 1.0, 1.0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 f.glRotatef(1.0, 0.0, 1.0, 1.0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3087
diff changeset
192 f.glColor4f(1.0, 1.0, 1.0, 1.0);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 f.glDrawArrays(GL_POINTS, 0, NB_PIXELS);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 SDL_GL_SwapBuffers();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 while (SDL_PollEvent(&event)) {
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3087
diff changeset
199 if (event.type == SDL_QUIT)
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 3087
diff changeset
200 done = 1;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 if (event.type == SDL_KEYDOWN)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 done = 1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 SDL_Delay(20);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 while (!done);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
3410
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
209 f.glDisableClientState(GL_VERTEX_ARRAY);
f4bc25567731 Optimizations.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
210
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 SDL_Quit();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 #else /* HAVE_OPENGLES */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 main(int argc, char *argv[])
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 {
3087
0b6f51c29267 Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
220 printf("No OpenGL ES support on this system\n");
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 return 1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 #endif /* HAVE_OPENGLES */