annotate dmglrender.cpp @ 91:4df8a7337e3e

Add simple 32bit texture version.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 18 Jan 2021 12:23:48 +0200
parents 3863ad92f8d8
children 28dd29f3a65f
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 #ifdef GL_GLEXT_PROTOTYPES
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #define DM_GLEXT_INIT(extproctype, extprocname) /* stub */
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #else
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #define DM_GLEXT_INIT(extproctype, extprocname) extproctype extprocname = NULL;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #include "dmglexts.h"
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #undef DM_GLEXT_INIT
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 static void dmGLCheckExtension(const std::string &name, bool &status)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 if (!SDL_GL_ExtensionSupported(name.c_str()))
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 status = false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 dmMsg(" - '%s' NOT supported.\n",
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 name.c_str());
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 static void * dmGLGetProcAddr(const std::string &name)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 void *ptr = SDL_GL_GetProcAddress(name.c_str());
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 if (ptr == NULL)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 dmMsg(" - '%s' NOT supported.\n");
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 return ptr;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 static void * dmGLExtInit(const std::string &name, bool &status)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 void *ptr;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 bool ok =
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 (ptr = dmGLGetProcAddr(name)) != NULL ||
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 (ptr = dmGLGetProcAddr(name + "EXT")) != NULL ||
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 (ptr = dmGLGetProcAddr(name + "ARB")) != NULL;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 if (!ok)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 status = false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 return ptr;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 #endif
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 static bool dmCompileShader(const GLenum stype, const std::string &src, GLuint &shader)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 GLint status;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 const char *tmp = src.c_str();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 shader = glCreateShader(stype);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 glShaderSource(shader, 1, &tmp, 0);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 glCompileShader(shader);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 if (status == GL_TRUE)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 else
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 GLint bufLen = 0;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &bufLen);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 if (bufLen > 0)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 char *buf = new char[bufLen];
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 glGetShaderInfoLog(shader, bufLen, NULL, buf);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 dmError("Shader compilation error:\n%s\n",
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 buf);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 delete[] buf;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 else
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 dmError("Shader compilation error occured, but no error information got.\n");
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 return false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 bool DMGLSimpleRenderer::checkErrors(void)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 bool ok = true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 GLenum err;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 while ((err = glGetError()) != GL_NO_ERROR)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 dmError("OpenGL error code: 0x%x (%d)\n", err);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 ok = false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 return ok;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
106 bool DMGLSimpleRenderer::initRenderer1(const char *title,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
107 const int width, const int height,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
108 const int sdlWindowHPos, const int sdlWindowVPos,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
109 const int sdlFlags)
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 // Set GL attributes
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
125 // Attempt to create a window
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
126 if (!DMSimpleRenderer::initRenderer1(
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
127 title,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
128 width, height,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
129 sdlWindowHPos, sdlWindowVPos,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
130 sdlFlags | SDL_WINDOW_OPENGL))
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
131 return false;
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 // Create OpenGL context
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
134 if ((sdlGLContext = SDL_GL_CreateContext(sdlWindow)) == NULL)
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 dmError("Unable to create SDL OpenGL context: %s\n",
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 SDL_GetError());
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 return false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 // If shaders are disabled, do not initialize OpenGL extensions
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 if (!useShaders)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 bool status = true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 dmMsg("Checking for required OpenGL extensions ..\n");
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 #ifndef GL_GLEXT_PROTOTYPES
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 dmGLCheckExtension("GL_ARB_shader_objects", status);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 dmGLCheckExtension("GL_ARB_shading_language_100", status);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 dmGLCheckExtension("GL_ARB_vertex_shader", status);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 dmGLCheckExtension("GL_ARB_fragment_shader", status);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 if (!status)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 dmError("One or more of the required OpenGL extensions not supported.\n");
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 return false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 #define DM_GLEXT_INIT(extproctype, extprocname) \
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 extprocname = (extproctype) dmGLExtInit(#extprocname, status);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 #include "dmglexts.h"
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 #endif
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 return status;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
168 #define TWIDTH 8
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
169 #define THEIGHT 8
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
170 static char texSrc8[TWIDTH * THEIGHT + 1] =
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 "##....##"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
175 "########"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
176 "##....##"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
177 "##....##"
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
178 "##....##";
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
179
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
180 static Uint32 texSrc32[TWIDTH * THEIGHT];
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
181
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
182
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
183 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
184 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 // Dump some information
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 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
187 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
188 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
189
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 if (!checkErrors())
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 return false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 // 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
194 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
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_PROJECTION);
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
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
199 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
200
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 glMatrixMode(GL_MODELVIEW);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 glLoadIdentity();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 // 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
205 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
206
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 // Enable smooth shading
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 glShadeModel(GL_SMOOTH);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 // 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
211 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
212
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 // Enable normal rescaling
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 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
215
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 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
217
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 // Setup depth buffer
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 glClearDepth(1.0f);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 // 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
222 glDepthFunc(GL_LEQUAL);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 // 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
225 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
226 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
227
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 // 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
229 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
230
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
231
69d7349dc5d3 Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
232 // 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
233 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
234 {
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
235 Uint8 *dp8 = ((Uint8 *) texSrc8) + yc * TWIDTH;
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
236 Uint32 *dp32 = ((Uint32 *) texSrc32) + yc * TWIDTH;
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
237
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
238 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
239 {
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
240 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
241 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
242 {
69d7349dc5d3 Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
243 case '.': col = 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
244 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
245 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
246 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
247 }
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
248 dp8[xc] = col;
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
249 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
250 }
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 }
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
69d7349dc5d3 Render a textured quad with bitmap letter 'A' in the bottom left corner as
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
253 // Upload to GPU texture
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
254 glGenTextures(1, &tex8);
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
255 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
256 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
257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
258 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
259 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
260
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
261 glGenTextures(2, &tex32);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
262 glBindTexture(GL_TEXTURE_2D, tex32);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
263 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
264 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
265 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
266 glBindTexture(GL_TEXTURE_2D, 0);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
267
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 return checkErrors();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 }
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
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 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
273 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 if (useShaders)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 {
68
701bef61dcf1 Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
276 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
277
701bef61dcf1 Remove OpenGL fs/vs shader ids from DMModel, as they are not needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
278 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
279 !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
280 return false;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 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
283 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
284 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
285 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
286 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
287 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
288 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 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
294 {
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
295 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
296 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
297
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
298 DMSimpleRenderer::shutdownRenderer();
62
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::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
303 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 int maxIndices;
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 if (useShaders)
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 // Enable shader program
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 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
310 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
311 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
312 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 // 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
315 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
316 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
317 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
318 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
319
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 // Render the model
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 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
322
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 // Add transforms
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 if (model.scaleSet)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 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
326
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 if (model.translateSet)
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 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
329
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 if (model.rotateSet)
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 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
333 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
334 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
335 }
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 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
338 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
339
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 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
341 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 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
343 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
344 }
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 // Restore
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 if (useShaders)
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 glUseProgram(0);
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 }
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
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 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
355 {
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
356 float qx, qy, qw, qh;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
357
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 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
359
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 glMatrixMode(GL_PROJECTION);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 glPushMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 glLoadIdentity();
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 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
365
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 glMatrixMode(GL_MODELVIEW);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 glPushMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 glLoadIdentity();
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 // 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
371 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
372 glDisable(GL_LIGHTING);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 glBegin(GL_QUADS);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 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
376 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
377 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
378
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 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
380 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
381 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
382 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 glEnd();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
385 // 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
386 glColor3ub(0xff, 0xff, 0xff);
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
387
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
388 qh = 0.35f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
389 qw = qh * 0.6f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
390 qx = 0;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
391 qy = 0;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
392
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
393 glEnable(GL_TEXTURE_2D);
90
3863ad92f8d8 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
394 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
395 glBegin(GL_QUADS);
91
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
396 glTexCoord2i(-1, 0); glVertex2f(qx , qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
397 glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
398 glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
399 glTexCoord2i(-1, -1); glVertex2f(qx , qy + qh);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
400 glEnd();
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
401
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
402 // Draw texture #2
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
403 qh = 0.25f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
404 qw = qh * 0.6f;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
405 qx = 1.0f - qw;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
406 qy = 1.0f - qh;
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
407
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
408 glBindTexture(GL_TEXTURE_2D, tex32);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
409 glBegin(GL_QUADS);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
410 glTexCoord2i(-1, 0); glVertex2f(qx , qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
411 glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
412 glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh);
4df8a7337e3e Add simple 32bit texture version.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
413 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
414 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
415 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
416 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
417
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 // 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
419 glMatrixMode(GL_PROJECTION);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 glPopMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 glMatrixMode(GL_MODELVIEW);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 glPopMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 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
426 glEnable(GL_LIGHTING);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 // Draw models
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 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
430 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 glPushMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 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
433 glPopMatrix();
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 }
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 }
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 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
459 {
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 (void) scene;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 (void) time;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 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
464 return true;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 }