annotate dmglrender.cpp @ 107:2b30217a3c39 default tip

Fix verbose build echos.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 29 Feb 2024 21:48:47 +0200
parents 50a69d327b4f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #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
14 #include "dmglexts.h"
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #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
16
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 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
19 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 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
21 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 status = false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 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
24 name.c_str());
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
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 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
30 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 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
32
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 if (ptr == NULL)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 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
35
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 return ptr;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 }
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
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 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
41 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 void *ptr;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 bool ok =
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 (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
45 (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
46 (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
47
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 if (!ok)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 status = false;
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 return ptr;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
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
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 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
56 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 GLint status;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 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
59
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 shader = glCreateShader(stype);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 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
62 glCompileShader(shader);
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 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
65 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
66 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 else
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 GLint bufLen = 0;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 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
71
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 if (bufLen > 0)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 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
75 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
76 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
77 buf);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 delete[] buf;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 else
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 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
83 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 return false;
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 }
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
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 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
90 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 bool ok = true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 GLenum err;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 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
94 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 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
96 ok = false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 return ok;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
102 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
103 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
104 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
105 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
106 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 // Set GL attributes
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 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
109 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
110 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
111
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_RED_SIZE, 8);
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_BLUE_SIZE, 8);
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_GREEN_SIZE, 8);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 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
116
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_DEPTH_SIZE, 24);
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_BUFFER_SIZE, 32);
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_DOUBLEBUFFER, 1);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
121 // 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
122 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
123 title,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
124 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
125 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
126 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
127 return false;
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 // 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
130 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
131 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 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
133 SDL_GetError());
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 return false;
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
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 // 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
138 if (!useShaders)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 return true;
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 bool status = true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 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
143
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 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
145 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
146 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
147 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
148 if (!status)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 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
151 return false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 #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
155 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
156 #include "dmglexts.h"
96
50a69d327b4f Remove support for GL_GLEXT_PROTOTYPES.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
157 #undef DM_GLEXT_INIT
62
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 return status;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
163 #define TWIDTH 8
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
164 #define THEIGHT 8
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
165 static char texSrc8[TWIDTH * THEIGHT + 1] =
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
166 "..%##%.."
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
167 ".%####%."
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
168 "%#*..*#%"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
169 "##....##"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
170 "########"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
171 "##....##"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
172 "##....##"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
173 "##....##";
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
174
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
175 static Uint32 texSrc32[TWIDTH * THEIGHT];
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
176
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
177
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
178 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
179 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 // Dump some information
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 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
182 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
183 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
184
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 if (!checkErrors())
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 return false;
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 // 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
189 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
190
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 glMatrixMode(GL_PROJECTION);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 glLoadIdentity();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
194 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
195
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 glMatrixMode(GL_MODELVIEW);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 glLoadIdentity();
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 // 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
200 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
201
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 // Enable smooth shading
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 glShadeModel(GL_SMOOTH);
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 the depth buffer
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 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
207
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 // Enable normal rescaling
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 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
210
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 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
212
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 // Setup depth buffer
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 glClearDepth(1.0f);
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 // 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
217 glDepthFunc(GL_LEQUAL);
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 // 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
220 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
221 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
222
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 // 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
224 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
225
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
226
69d7349dc5d3 Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
227 // 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
228 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
229 {
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
230 Uint8 *dp8 = ((Uint8 *) texSrc8) + yc * TWIDTH;
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
231 Uint32 *dp32 = ((Uint32 *) texSrc32) + yc * TWIDTH;
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
232
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
233 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
234 {
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
235 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
236 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
237 {
69d7349dc5d3 Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
238 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
239 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
240 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
241 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
242 }
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
243 dp8[xc] = col;
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
244 dp32[xc] = col | (col << 8) | (col << 16);
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
245 }
69d7349dc5d3 Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
246 }
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 // Upload to GPU texture
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
249 glGenTextures(1, &tex8);
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
250 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
251 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
252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
253 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
254 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
255
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
256 glGenTextures(2, &tex32);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
257 glBindTexture(GL_TEXTURE_2D, tex32);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
260 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TWIDTH, THEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, texSrc32);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
261 glBindTexture(GL_TEXTURE_2D, 0);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
262
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 return checkErrors();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 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
268 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 if (useShaders)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 {
68
701bef61dcf1 Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
271 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
272
701bef61dcf1 Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
273 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
274 !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
275 return false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 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
278 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
279 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
280 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
281 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
282 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
283 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286
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 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
289 {
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
290 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
291 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
292
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
293 DMSimpleRenderer::shutdownRenderer();
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 }
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
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 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
298 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 int maxIndices;
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 if (useShaders)
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 // Enable shader program
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 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
305 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
306 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
307 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 // 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
310 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
311 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
312 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
313 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
314
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 // Render the model
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 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
317
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 // Add transforms
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 if (model.scaleSet)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 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
321
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 if (model.translateSet)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 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
324
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 if (model.rotateSet)
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 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
328 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
329 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
330 }
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 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
333 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
334
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 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
336 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 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
338 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
339 }
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 // Restore
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 if (useShaders)
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 glUseProgram(0);
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 }
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 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
350 {
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
351 float qx, qy, qw, qh;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
352
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 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
354
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 glMatrixMode(GL_PROJECTION);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 glPushMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 glLoadIdentity();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 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
360
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 glMatrixMode(GL_MODELVIEW);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 glPushMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 glLoadIdentity();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 // 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
366 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
367 glDisable(GL_LIGHTING);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 glBegin(GL_QUADS);
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 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
371 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
372 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
373
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 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
375 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
376 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
377 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 glEnd();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
380 // Draw texture #1
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
381 glColor3ub(0xff, 0xff, 0xff);
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
382
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
383 qh = 0.35f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
384 qw = qh * 0.6f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
385 qx = 0;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
386 qy = 0;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
387
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
388 glEnable(GL_TEXTURE_2D);
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
389 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
390 glBegin(GL_QUADS);
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
391 glTexCoord2i(-1, 0); glVertex2f(qx , qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
392 glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
393 glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
394 glTexCoord2i(-1, -1); glVertex2f(qx , qy + qh);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
395 glEnd();
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
396
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
397 // Draw texture #2
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
398 qh = 0.25f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
399 qw = qh * 0.6f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
400 qx = 1.0f - qw;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
401 qy = 1.0f - qh;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
402
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
403 glBindTexture(GL_TEXTURE_2D, tex32);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
404 glBegin(GL_QUADS);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
405 glTexCoord2i(-1, 0); glVertex2f(qx , qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
406 glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
407 glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
408 glTexCoord2i(-1, -1); glVertex2f(qx , qy + qh);
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
409 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
410 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
411 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
412
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 // 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
414 glMatrixMode(GL_PROJECTION);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 glPopMatrix();
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 glMatrixMode(GL_MODELVIEW);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 glPopMatrix();
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 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
421 glEnable(GL_LIGHTING);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 // Draw models
92
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
424 glPushMatrix();
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
425 glRotatef(time * 360.0, 0, 1, 0);
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
426
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 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
428 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 glPushMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 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
431 glPopMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 }
92
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
433
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
434 glPopMatrix();
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 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
439 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 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
441 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
442 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
443 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
444 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
445 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 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
450 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 (void) camera;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 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
454 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 }