summaryrefslogtreecommitdiffstats
path: root/Renderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Renderer.cpp')
-rw-r--r--Renderer.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/Renderer.cpp b/Renderer.cpp
index bf9aadb..558e415 100644
--- a/Renderer.cpp
+++ b/Renderer.cpp
@@ -19,11 +19,10 @@
#include "Renderer.h"
#include "BSPTree.h"
+#include "gl.h"
namespace Zoom {
-const Renderer::RenderVisitor Renderer::renderVisitor = Renderer::RenderVisitor();
-
void Renderer::render(const BSPTree &tree) {
vmml::mat4f transform, inverseTransform;
glGetFloatv(GL_MODELVIEW_MATRIX, transform.array);
@@ -38,14 +37,39 @@ void Renderer::render(const BSPTree &tree) {
}
+void Renderer::render(const std::list<BSPTree::TriangleRecord> &triangles) {
+ glBegin(GL_TRIANGLES);
+ for(std::list<BSPTree::TriangleRecord>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
+ renderTriangle(t->triangle);
+ }
+ glEnd();
+}
+
void Renderer::renderTriangle(const Triangle &t) {
glColor4fv(t.getColor().array);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, t.getColor().array);
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (t.getColor()/2).array);
- glNormal3fv(t.getNormal().array);
+ if(t.getTexture() != lastTexture) {
+ glEnd();
+
+ if(t.getTexture()) {
+ glBindTexture(GL_TEXTURE_2D, t.getTexture());
+
+ if(!lastTexture) {
+ glEnable(GL_TEXTURE_2D);
+ }
+ }
+ else {
+ glDisable(GL_TEXTURE_2D);
+ }
+
+ lastTexture = t.getTexture();
+
+ glBegin(GL_TRIANGLES);
+ }
for(int i = 0; i < 3; ++i) {
+ glTexCoord2fv(t.getTexCoords(i).array);
+ glNormal3fv(t.getNormal(i).array);
glVertex3fv(t.getVertex(i).array);
}
}