Mercurial > hg > forks > gldragon
annotate dmglrender.cpp @ 80:98e077d9d361
List the keyboard controls in --help.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Mar 2020 14:37:59 +0200 |
parents | 701bef61dcf1 |
children | 69d7349dc5d3 |
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 |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
168 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
|
169 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 // Dump some information |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 if (!checkErrors()) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 return false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 // 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
|
179 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
|
180 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 glMatrixMode(GL_PROJECTION); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 glLoadIdentity(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
184 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
|
185 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 glMatrixMode(GL_MODELVIEW); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 glLoadIdentity(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 // 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
|
190 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
|
191 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 // Enable smooth shading |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 glShadeModel(GL_SMOOTH); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 // 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
|
196 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
|
197 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 // Enable normal rescaling |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 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
|
200 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 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
|
202 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 // Setup depth buffer |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 glClearDepth(1.0f); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 // 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
|
207 glDepthFunc(GL_LEQUAL); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 // 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
|
210 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
|
211 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
|
212 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 // 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
|
214 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
|
215 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 return checkErrors(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 } |
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 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 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
|
221 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 if (useShaders) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 { |
68
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
224 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
|
225 |
701bef61dcf1
Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
226 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
|
227 !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
|
228 return false; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 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
|
242 { |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
243 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
|
244 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
|
245 |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
246 DMSimpleRenderer::shutdownRenderer(); |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 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
|
251 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 int maxIndices; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 if (useShaders) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 // Enable shader program |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 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
|
258 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
|
259 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
|
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 // 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 // Render the model |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 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
|
270 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 // Add transforms |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 if (model.scaleSet) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 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
|
274 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 if (model.translateSet) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 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
|
277 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 if (model.rotateSet) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 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
|
286 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
|
287 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 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
|
289 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 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
|
291 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
|
292 } |
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 // Restore |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 if (useShaders) |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 glUseProgram(0); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 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
|
303 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 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
|
305 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 glMatrixMode(GL_PROJECTION); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 glPushMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 glLoadIdentity(); |
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 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
|
311 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 glMatrixMode(GL_MODELVIEW); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 glPushMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 glLoadIdentity(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 // 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
|
317 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
|
318 glDisable(GL_LIGHTING); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 glBegin(GL_QUADS); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 glEnd(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 // 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
|
332 glMatrixMode(GL_PROJECTION); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 glPopMatrix(); |
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 glMatrixMode(GL_MODELVIEW); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 glPopMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 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
|
339 glEnable(GL_LIGHTING); |
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 // Draw models |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 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
|
343 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 glPushMatrix(); |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 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
|
346 glPopMatrix(); |
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 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 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
|
352 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 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
|
363 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 (void) camera; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 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
|
367 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 } |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 |
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 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
|
372 { |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 (void) scene; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 (void) time; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 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
|
377 return true; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 } |