Mercurial > hg > forks > gldragon
annotate dmglrender.cpp @ 90:3863ad92f8d8
Rename a variable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Jan 2021 14:33:18 +0200 |
parents | 69d7349dc5d3 |
children | 4df8a7337e3e |
rev | line source |
---|---|
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // GLDragon - OpenGL PLY model viewer / simple benchmark |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // -- OpenGL rendering of DMSimpleScene |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // (C) Copyright 2019 Tecnic Software productions (TNSP) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 // |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 // See file "COPYING" for license information. |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 // |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "dmglrender.h" |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include <GL/glu.h> |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #ifdef GL_GLEXT_PROTOTYPES |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #define DM_GLEXT_INIT(extproctype, extprocname) /* stub */ |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #else |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 #define DM_GLEXT_INIT(extproctype, extprocname) extproctype extprocname = NULL; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 #include "dmglexts.h" |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 #undef DM_GLEXT_INIT |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 static void dmGLCheckExtension(const std::string &name, bool &status) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 if (!SDL_GL_ExtensionSupported(name.c_str())) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 status = false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 dmMsg(" - '%s' NOT supported.\n", |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 name.c_str()); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 static void * dmGLGetProcAddr(const std::string &name) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 void *ptr = SDL_GL_GetProcAddress(name.c_str()); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 if (ptr == NULL) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 dmMsg(" - '%s' NOT supported.\n"); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 return ptr; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 static void * dmGLExtInit(const std::string &name, bool &status) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 void *ptr; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 bool ok = |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 (ptr = dmGLGetProcAddr(name)) != NULL || |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 (ptr = dmGLGetProcAddr(name + "EXT")) != NULL || |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 (ptr = dmGLGetProcAddr(name + "ARB")) != NULL; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 if (!ok) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 status = false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 return ptr; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 #endif |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 static bool dmCompileShader(const GLenum stype, const std::string &src, GLuint &shader) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 GLint status; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 const char *tmp = src.c_str(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 shader = glCreateShader(stype); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 glShaderSource(shader, 1, &tmp, 0); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 glCompileShader(shader); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 glGetShaderiv(shader, GL_COMPILE_STATUS, &status); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 if (status == GL_TRUE) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 else |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 GLint bufLen = 0; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &bufLen); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 if (bufLen > 0) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 char *buf = new char[bufLen]; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 glGetShaderInfoLog(shader, bufLen, NULL, buf); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 dmError("Shader compilation error:\n%s\n", |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 buf); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 delete[] buf; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 else |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 dmError("Shader compilation error occured, but no error information got.\n"); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 return false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 bool DMGLSimpleRenderer::checkErrors(void) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 bool ok = true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 GLenum err; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 while ((err = glGetError()) != GL_NO_ERROR) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 dmError("OpenGL error code: 0x%x (%d)\n", err); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 ok = false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 return ok; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
106 bool DMGLSimpleRenderer::initRenderer1(const char *title, |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
107 const int width, const int height, |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
108 const int sdlWindowHPos, const int sdlWindowVPos, |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
109 const int sdlFlags) |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 // Set GL attributes |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
125 // Attempt to create a window |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
126 if (!DMSimpleRenderer::initRenderer1( |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
127 title, |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
128 width, height, |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
129 sdlWindowHPos, sdlWindowVPos, |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
130 sdlFlags | SDL_WINDOW_OPENGL)) |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
131 return false; |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 // Create OpenGL context |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
134 if ((sdlGLContext = SDL_GL_CreateContext(sdlWindow)) == NULL) |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 dmError("Unable to create SDL OpenGL context: %s\n", |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 SDL_GetError()); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 return false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 // If shaders are disabled, do not initialize OpenGL extensions |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 if (!useShaders) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 bool status = true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 dmMsg("Checking for required OpenGL extensions ..\n"); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 #ifndef GL_GLEXT_PROTOTYPES |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 dmGLCheckExtension("GL_ARB_shader_objects", status); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 dmGLCheckExtension("GL_ARB_shading_language_100", status); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 dmGLCheckExtension("GL_ARB_vertex_shader", status); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 dmGLCheckExtension("GL_ARB_fragment_shader", status); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 if (!status) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 dmError("One or more of the required OpenGL extensions not supported.\n"); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 return false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 #define DM_GLEXT_INIT(extproctype, extprocname) \ |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 extprocname = (extproctype) dmGLExtInit(#extprocname, status); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 #include "dmglexts.h" |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 #endif |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 return status; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 |
90 | 168 #define TWIDTH 8 |
169 #define THEIGHT 8 | |
170 static char texSrc8[TWIDTH * THEIGHT + 1] = | |
171 "..%##%.." | |
172 ".%####%." | |
173 "%#*..*#%" | |
174 "##....##" | |
175 "########" | |
176 "##....##" | |
177 "##....##" | |
178 "##....##"; | |
179 | |
180 | |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
181 bool DMGLSimpleRenderer::initRenderer2(void) |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 // Dump some information |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER)); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION)); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 if (!checkErrors()) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 return false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 // Setup the window and view port |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
192 glViewport(0, 0, windowWidth, windowHeight); |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 glMatrixMode(GL_PROJECTION); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 glLoadIdentity(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
197 gluPerspective(45.0f, GLfloat(windowWidth) / GLfloat(windowHeight), 0.1f, 1000.0f); |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 glMatrixMode(GL_MODELVIEW); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 glLoadIdentity(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 // Enable back face culling |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 glEnable(GL_CULL_FACE); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 // Enable smooth shading |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 glShadeModel(GL_SMOOTH); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 // Enable the depth buffer |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 glEnable(GL_DEPTH_TEST); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 // Enable normal rescaling |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 glEnable(GL_RESCALE_NORMAL); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 glEnable(GL_COLOR_MATERIAL); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 // Setup depth buffer |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 glClearDepth(1.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 // Set the depth buffer function |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 glDepthFunc(GL_LEQUAL); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 // Enable vertex and and normal arrays |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 glEnableClientState(GL_VERTEX_ARRAY); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 glEnableClientState(GL_NORMAL_ARRAY); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 // Set correct perspective correction |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
229 |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
230 // Create texture bitmap |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
231 |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
232 for (int yc = 0; yc < THEIGHT; yc++) |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
233 { |
90 | 234 Uint8 *dp8 = ((Uint8 *) texSrc8) + yc * TWIDTH; |
235 | |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
236 for (int xc = 0; xc < TWIDTH; xc++) |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
237 { |
90 | 238 Uint8 col = dp8[xc]; |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
239 switch (col) |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
240 { |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
241 case '.': col = 0; break; |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
242 case '#': col = 255; break; |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
243 case '*': col = 128; break; |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
244 default: col = 192; break; |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
245 } |
90 | 246 dp8[xc] = col; |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
247 } |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
248 } |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
249 |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
250 // Upload to GPU texture |
90 | 251 glGenTextures(1, &tex8); |
252 glBindTexture(GL_TEXTURE_2D, tex8); | |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
90 | 255 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, TWIDTH, THEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texSrc8); |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
256 glBindTexture(GL_TEXTURE_2D, 0); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
257 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 return checkErrors(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 bool DMGLSimpleRenderer::compileModelShaders(DMModel &model) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 if (useShaders) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 { |
68
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
266 GLuint id_fs, id_vs; |
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
267 |
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
268 if (!dmCompileShader(GL_FRAGMENT_SHADER, model.fragShaderStr, id_fs) || |
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
269 !dmCompileShader(GL_VERTEX_SHADER, model.vertShaderStr, id_vs)) |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 return false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 model.id_prog = glCreateProgram(); |
68
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
273 glAttachShader(model.id_prog, id_fs); |
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
274 glAttachShader(model.id_prog, id_vs); |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 glLinkProgram(model.id_prog); |
68
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
276 glDeleteShader(id_fs); |
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
277 glDeleteShader(id_vs); |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 void DMGLSimpleRenderer::shutdownRenderer(void) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 { |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
285 if (sdlGLContext != NULL) |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
286 SDL_GL_DeleteContext(sdlGLContext); |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
287 |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
288 DMSimpleRenderer::shutdownRenderer(); |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 void DMGLSimpleRenderer::drawModel(const DMSimpleScene &scene, const DMModel &model, const float time) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 int maxIndices; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 if (useShaders) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 // Enable shader program |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 glUseProgram(model.id_prog); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 glUniform1i(glGetUniformLocation(model.id_prog, "nlights"), scene.lights.size()); |
65
71f6c5cc8eec
Add 'ftime' uniform for shaders, which is time in milliseconds from start of rendering loop.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
301 glUniform1f(glGetUniformLocation(model.id_prog, "ftime"), time); |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 // Set the material of the model |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 glMateriali(GL_FRONT, GL_SHININESS, model.material.shininess); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 glMaterialfv(GL_FRONT, GL_SPECULAR, model.material.specular.values); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 glColor4fv(model.material.diffuse.values); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 // Render the model |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 // Add transforms |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 if (model.scaleSet) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 glScalef(model.scale.x, model.scale.y, model.scale.z); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 if (model.translateSet) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 glTranslatef(model.translate.x, model.translate.y, model.translate.z); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 if (model.rotateSet) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 glRotatef(model.rotate.x, 1.0f, 0.0f, 0.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 glRotatef(model.rotate.y, 0.0f, 1.0f, 0.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 glRotatef(model.rotate.z, 0.0f, 0.0f, 1.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 glVertexPointer(3, GL_FLOAT, 0, &model.vertices[0]); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 glNormalPointer( GL_FLOAT, 0, &model.normals[0]); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 for (int n = 0; n < model.nfaces; n += maxIndices) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 const int count = std::min(maxIndices, model.nfaces - n); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_INT, &model.faces[n * 3]); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 // Restore |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 if (useShaders) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 glUseProgram(0); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 void DMGLSimpleRenderer::drawScene(const DMSimpleScene &scene, const float time) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 glClear(GL_DEPTH_BUFFER_BIT); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 glMatrixMode(GL_PROJECTION); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 glPushMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 glLoadIdentity(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 glOrtho(0.0, 1.0, 0.0, 1.0, -1, 1); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 glMatrixMode(GL_MODELVIEW); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 glPushMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 glLoadIdentity(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 // Draw the background gradient |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 glDisable(GL_DEPTH_TEST); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 glDisable(GL_LIGHTING); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 glBegin(GL_QUADS); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 glColor3ub(0x3B, 0x3B, 0x75); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 glVertex2f(0.0f, 0.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 glVertex2f(1.0f, 0.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 glColor3ub(0x00, 0x00, 0x00); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 glVertex2f(1.0f, 1.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 glVertex2f(0.0f, 1.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 glEnd(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
373 // Draw texture |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
374 glColor3ub(0xff, 0xff, 0xff); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
375 glEnable(GL_TEXTURE_2D); |
90 | 376 glBindTexture(GL_TEXTURE_2D, tex8); |
83
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
377 glBegin(GL_QUADS); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
378 float s = 0.50f; |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
379 glTexCoord2i(-1, 0); glVertex2f(0, 0); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
380 glTexCoord2i( 0, 0); glVertex2f(s * 0.6f, 0); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
381 glTexCoord2i( 0, -1); glVertex2f(s * 0.6f, s); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
382 glTexCoord2i(-1, -1); glVertex2f(0, s); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
383 glEnd(); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
384 glBindTexture(GL_TEXTURE_2D, 0); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
385 glDisable(GL_TEXTURE_2D); |
69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
386 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 // Restore the 3D projection |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 glMatrixMode(GL_PROJECTION); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
389 glPopMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
391 glMatrixMode(GL_MODELVIEW); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 glPopMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 glEnable(GL_DEPTH_TEST); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 glEnable(GL_LIGHTING); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 // Draw models |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 for (const DMModel &model : scene.models) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 glPushMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
401 drawModel(scene, model, time); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
402 glPopMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
404 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 bool DMGLSimpleRenderer::setupLight(const int n, DMLight &light) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 glEnable(GL_LIGHT0 + n); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 glLightfv(GL_LIGHT0 + n, GL_AMBIENT, light.color.ambient.values); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 glLightfv(GL_LIGHT0 + n, GL_DIFFUSE, light.color.diffuse.values); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
412 glLightfv(GL_LIGHT0 + n, GL_SPECULAR, light.color.specular.values); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 glLightfv(GL_LIGHT0 + n, GL_POSITION, light.position.values); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
415 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 bool DMGLSimpleRenderer::setupCamera(DMCamera &camera) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 (void) camera; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 gluLookAt(0, 0.12, 0.24, 0, 0.12, 0, 0, 1, 0); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
424 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
425 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
426 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
427 bool DMGLSimpleRenderer::animate(DMSimpleScene &scene, const float time) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
428 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 (void) scene; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 (void) time; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
432 glRotatef(2.0f, 0, 1, 0); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
433 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
434 } |