Skip to content

Commit 5158093

Browse files
author
alfonse
committed
Basic scene graph system is in place.
1 parent 51821da commit 5158093

File tree

13 files changed

+4250
-34
lines changed

13 files changed

+4250
-34
lines changed

Documents/Illumination/Tutorial 13.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,11 @@ void main()
166166
we transform the camera-space position to clip-space as normal.</para>
167167
<para>The output <varname>mapping</varname> is a value that is used by the fragment
168168
shader, as we will see below.</para>
169-
<para>Since this vertex shader takes no inputs, our vertex array object does not need to
170-
contain anything either. That is, we never call
169+
<para><indexterm>
170+
<primary>Vertex Array Object</primary>
171+
<secondary>empty</secondary>
172+
</indexterm>Since this vertex shader takes no inputs, our vertex array object does
173+
not need to contain anything either. That is, we never call
171174
<function>glEnableVertexAttribArray</function> on the VAO. Since no attribute
172175
arrays are enabled, we also have no need for a buffer object to store vertex array
173176
data. So we never call <function>glVertexAttribPointer</function>. We simply

Tut 13 Impostors/BasicImpostor.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ void CreateMaterials()
272272
}
273273

274274
GLuint g_imposterVAO;
275-
GLuint g_imposterVBO;
276275

277276
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
278277
void init()
@@ -326,17 +325,8 @@ void init()
326325

327326
glBindBuffer(GL_UNIFORM_BUFFER, 0);
328327

329-
glGenBuffers(1, &g_imposterVBO);
330-
glBindBuffer(GL_ARRAY_BUFFER, g_imposterVBO);
331-
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(float), NULL, GL_STATIC_DRAW);
332-
328+
//Empty Vertex Array Object.
333329
glGenVertexArrays(1, &g_imposterVAO);
334-
// glBindVertexArray(g_imposterVAO);
335-
// glEnableVertexAttribArray(0);
336-
// glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, (void*)(0));
337-
338-
glBindVertexArray(0);
339-
glBindBuffer(GL_ARRAY_BUFFER, 0);
340330

341331
CreateMaterials();
342332
}

Tut 17 Spotlight on Textures/Double Projection.cpp

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "../framework/Scene.h"
1919
#include <glm/glm.hpp>
2020
#include <glm/gtc/type_ptr.hpp>
21+
#include <glm/gtc/quaternion.hpp>
2122
#include <glm/gtc/matrix_transform.hpp>
2223

2324
#define ARRAY_COUNT( array ) (sizeof( array ) / (sizeof( array[0] ) * (sizeof( array ) != sizeof(void*) || sizeof( array[0] ) <= sizeof(void*))))
@@ -172,7 +173,7 @@ void LoadTextures()
172173
//View setup.
173174
glutil::ViewData g_initialView =
174175
{
175-
glm::vec3(-60.257084f, 10.947238f, 62.636356f),
176+
glm::vec3(0.0f, 0.0f, 0.0f),
176177
glm::fquat(-0.972817f, -0.099283f, -0.211198f, -0.020028f),
177178
30.0f,
178179
0.0f
@@ -196,21 +197,55 @@ namespace
196197
}
197198

198199
Framework::Scene *g_pScene = NULL;
200+
std::vector<Framework::NodeRef> g_nodes;
201+
Framework::Timer g_timer(Framework::Timer::TT_LOOP, 10.0f);
199202

200-
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
201-
void init()
203+
class ColorUniformBinder : public Framework::StateBinder
202204
{
203-
try
205+
public:
206+
ColorUniformBinder()
207+
: m_clrUnif(-1)
208+
, m_clr(0.0f, 0.0f, 0.0f, 1.0f) {}
209+
210+
void AssociateWithProgram(GLuint prog, const std::string &unifName)
204211
{
205-
g_pScene = new Framework::Scene("test.scene");
206-
// InitializePrograms();
212+
m_clrUnif = glGetUniformLocation(prog, unifName.c_str());
207213
}
208-
catch(std::exception &except)
214+
215+
void SetColor(const glm::vec4 &clr) { m_clr = clr; }
216+
217+
virtual void BindState() const
209218
{
210-
printf("%s\n", except.what());
211-
throw;
219+
glUniform4fv(m_clrUnif, 1, glm::value_ptr(m_clr));
212220
}
213221

222+
virtual void UnbindState() const {}
223+
224+
private:
225+
GLint m_clrUnif;
226+
glm::vec4 m_clr;
227+
};
228+
229+
ColorUniformBinder g_clrUnif;
230+
231+
void LoadAndSetupScene()
232+
{
233+
g_nodes.clear();
234+
g_pScene = new Framework::Scene("sceneTest.xml");
235+
g_nodes.push_back(g_pScene->FindNode("blue"));
236+
g_nodes.push_back(g_pScene->FindNode("user"));
237+
238+
GLuint colorProg = g_pScene->FindProgram("p_colored");
239+
240+
//No more things that can throw.
241+
g_clrUnif.AssociateWithProgram(colorProg, "objectColor");
242+
g_nodes[1].SetStateBinder(&g_clrUnif);
243+
g_clrUnif.SetColor(glm::vec4(0.1f, 1.0f, 0.1f, 1.0f));
244+
}
245+
246+
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
247+
void init()
248+
{
214249
glutMouseFunc(MouseButton);
215250
glutMotionFunc(MouseMotion);
216251
glutMouseWheelFunc(MouseWheel);
@@ -227,6 +262,7 @@ void init()
227262
glDepthFunc(GL_LEQUAL);
228263
glDepthRange(depthZNear, depthZFar);
229264
glEnable(GL_DEPTH_CLAMP);
265+
glEnable(GL_FRAMEBUFFER_SRGB);
230266

231267
//Setup our Uniform Buffers
232268
glGenBuffers(1, &g_projectionUniformBuffer);
@@ -236,6 +272,17 @@ void init()
236272
glBindBufferRange(GL_UNIFORM_BUFFER, g_projectionBlockIndex, g_projectionUniformBuffer,
237273
0, sizeof(ProjectionBlock));
238274

275+
try
276+
{
277+
LoadAndSetupScene();
278+
// InitializePrograms();
279+
}
280+
catch(std::exception &except)
281+
{
282+
printf("%s\n", except.what());
283+
throw;
284+
}
285+
239286
/*
240287
glGenBuffers(1, &g_lightUniformBuffer);
241288
glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
@@ -265,9 +312,16 @@ void display()
265312
if(!g_pScene)
266313
return;
267314

315+
g_timer.Update();
316+
268317
glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
269318
glClearDepth(1.0f);
270319
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
320+
321+
g_nodes[0].NodeSetOrient(glm::rotate(glm::fquat(),
322+
360.0f * g_timer.GetAlpha(), glm::vec3(0.0f, 1.0f, 0.0f)));
323+
324+
g_pScene->Render(g_viewPole.CalcMatrix());
271325
/*
272326
if(!g_pLightEnv)
273327
return;
@@ -368,8 +422,9 @@ void display()
368422
}
369423
}
370424
371-
glutPostRedisplay();
372-
*/
425+
*/
426+
427+
glutPostRedisplay();
373428
glutSwapBuffers();
374429
}
375430

@@ -406,6 +461,34 @@ void keyboard(unsigned char key, int x, int y)
406461
glutLeaveMainLoop();
407462
return;
408463
case 32:
464+
g_nodes[0].NodeSetTrans(glm::vec3(0.0f, 0.0f, 0.0f));
465+
break;
466+
case 'i':
467+
g_nodes[0].NodeOffset(glm::vec3(0.0f, 1.0f, 0.0f));
468+
break;
469+
case 'j':
470+
g_nodes[0].NodeOffset(glm::vec3(0.0f, -1.0f, 0.0f));
471+
break;
472+
case '\r':
473+
{
474+
std::auto_ptr<Framework::Scene> pOldScene(g_pScene);
475+
g_pScene = NULL;
476+
std::vector<Framework::NodeRef> tmpNodes;
477+
tmpNodes.swap(g_nodes);
478+
try
479+
{
480+
LoadAndSetupScene();
481+
}
482+
catch(std::exception &except)
483+
{
484+
printf("Failed to reload, due to: %s\n", except.what());
485+
if(g_pScene)
486+
delete g_pScene;
487+
g_pScene = pOldScene.release();
488+
g_nodes.swap(tmpNodes);
489+
return;
490+
}
491+
}
409492
break;
410493
}
411494

framework/Mesh.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ namespace Framework
260260
}
261261

262262
strStream.flush();
263-
const std::string &strTest = strStream.str();
264263

265264
//Parse the text stream.
266265
pAttribType->ParseFunc(dataArray, strStream);

0 commit comments

Comments
 (0)