|
From: Tapio V. <aa...@us...> - 2009-11-11 17:58:16
|
Module: performous
Branch: master
Commit: 0f84502c418bdd4eb5dbad3acc7e0edb87970995
Author: Tapio Vierros <tap...@gm...>
Date: Wed Nov 11 19:57:23 2009 +0200
Added possibility to texture 3d objects.
---
game/3dobject.cc | 1 -
game/3dobject.hh | 16 ++++++++++------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/game/3dobject.cc b/game/3dobject.cc
index f4e5a2e..60e9e52 100644
--- a/game/3dobject.cc
+++ b/game/3dobject.cc
@@ -90,7 +90,6 @@ void Object3d::generateDisplayList() {
if (m_displist != 0) glDeleteLists(m_displist, 1);
m_displist = glGenLists(1);
glutil::DisplayList displist(m_displist, GL_COMPILE);
- //UseTexture tex(*m_texture);
std::vector<Face>::const_iterator it;
// Iterate through faces
for (it = m_faces.begin(); it != m_faces.end(); it++) {
diff --git a/game/3dobject.hh b/game/3dobject.hh
index 38ea1fc..585084b 100644
--- a/game/3dobject.hh
+++ b/game/3dobject.hh
@@ -6,6 +6,7 @@
#include <stdexcept>
#include <string>
+#include <boost/scoped_ptr.hpp>
#include <boost/noncopyable.hpp>
#include "surface.hh"
#include "glutil.hh"
@@ -40,7 +41,7 @@ class Object3d: boost::noncopyable {
std::vector<Vertex> m_normals;
std::vector<Face> m_faces;
GLuint m_displist;
- //boost::scoped_ptr<Texture> m_texture;
+ boost::scoped_ptr<Texture> m_texture;
/// load a Wavefront .obj 3d object file
void loadWavefrontObj(std::string filepath, float scale = 1.0);
/// generates a display list for the object
@@ -48,23 +49,26 @@ class Object3d: boost::noncopyable {
public:
/// constructors
Object3d(): m_displist(0) {};
- Object3d(std::string filepath, float scale = 1.0): m_displist(0) {
- load(filepath, scale);
+ Object3d(std::string filepath, std::string texturepath = "", float scale = 1.0): m_displist(0) {
+ load(filepath, texturepath, scale);
}
/// destructor
~Object3d() {
if (m_displist != 0) glDeleteLists(m_displist, 1);
}
/// load a new object file
- void load(std::string filepath, float scale = 1.0) {
- //m_texture.reset(new Texture(getThemePath("button.svg")));
+ void load(std::string filepath, std::string texturepath = "", float scale = 1.0) {
+ if (!texturepath.empty()) m_texture.reset(new Texture(texturepath));
loadWavefrontObj(filepath, scale);
generateDisplayList();
}
/// draws the object
void draw(float x = 0, float y = 0, float z = 0) const {
glTranslatef(x, y, z);
- glCallList(m_displist);
+ if (m_texture) {
+ UseTexture tex(*m_texture);
+ glCallList(m_displist);
+ } else glCallList(m_displist);
glTranslatef(-x, -y, -z);
}
};
|