added model loading into opengl. not yet seeing output.
This commit is contained in:
parent
0105bfe430
commit
92c27a1ef8
4 changed files with 87 additions and 7 deletions
|
@ -20,8 +20,8 @@
|
||||||
class GameWindow : public endofthejedi::GLWindow {
|
class GameWindow : public endofthejedi::GLWindow {
|
||||||
private:
|
private:
|
||||||
Game* m_game;
|
Game* m_game;
|
||||||
endofthejedi::RendererPolygon2d m_renderer;
|
//endofthejedi::RendererPolygon2d m_renderer;
|
||||||
//endofthejedi::RendererPolygon3d m_renderer;
|
endofthejedi::RendererPolygon3d m_renderer;
|
||||||
//endofthejedi::RendererRayTracer m_renderer;
|
//endofthejedi::RendererRayTracer m_renderer;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -24,6 +24,10 @@ class PolygonModel {
|
||||||
|
|
||||||
bool import()
|
bool import()
|
||||||
{
|
{
|
||||||
|
m_vbo_id_position = 0;
|
||||||
|
m_vbo_id_normal = 0;
|
||||||
|
m_numVertices = 0;
|
||||||
|
|
||||||
// Create an instance of the Importer class
|
// Create an instance of the Importer class
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
// And have it read the given file with some example postprocessing
|
// And have it read the given file with some example postprocessing
|
||||||
|
@ -51,6 +55,75 @@ class PolygonModel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool loadIntoOpenGl()
|
||||||
|
{
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glGenBuffers(1, &m_vbo_id_position); // Generate buffer
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id_position); // Bind buffer
|
||||||
|
|
||||||
|
glVertexAttribPointer(0,
|
||||||
|
3, // three floats per vertex
|
||||||
|
GL_FLOAT, // Data is floating point type
|
||||||
|
GL_FALSE, // No fixed point scaling
|
||||||
|
0, // stride: no
|
||||||
|
NULL); // No offset
|
||||||
|
|
||||||
|
// fill buffer with the loaded mesh position data
|
||||||
|
glBufferData(
|
||||||
|
GL_ARRAY_BUFFER, // Buffer target
|
||||||
|
3 * m_numVertices * sizeof(float), // Buffer data size
|
||||||
|
m_data_position.data(), // Buffer data pointer
|
||||||
|
GL_STATIC_DRAW); // Usage - Data never changes;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
#if 0
|
||||||
|
// 2 holds normal data
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glGenBuffers(1, &(model->vbo_normal)); // Generate buffer
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, model->vbo_normal); // Bind buffer
|
||||||
|
|
||||||
|
glVertexAttribPointer(2,
|
||||||
|
3, // three floats per normal
|
||||||
|
GL_FLOAT, // Data is floating point type
|
||||||
|
GL_FALSE, // No fixed point scaling
|
||||||
|
0, // stride: no
|
||||||
|
NULL); // No offset
|
||||||
|
|
||||||
|
// Fill bound buffer
|
||||||
|
glBufferData(
|
||||||
|
GL_ARRAY_BUFFER, // Buffer target
|
||||||
|
3*model->numVertices*sizeof(float), // Buffer data size
|
||||||
|
model->normals, // Buffer data pointer
|
||||||
|
GL_STATIC_DRAW); // Usage - Data never changes;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bind()
|
||||||
|
{
|
||||||
|
// bind position vbo
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id_position);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
#if 0
|
||||||
|
// bind normal vbo
|
||||||
|
GLuint normalLoc = glGetAttribLocation(program, "attr_normal");
|
||||||
|
glEnableVertexAttribArray(normalLoc);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo_normal);
|
||||||
|
glVertexAttribPointer(normalLoc, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, m_numVertices);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool copyVertices(const aiScene *scene)
|
bool copyVertices(const aiScene *scene)
|
||||||
{
|
{
|
||||||
|
@ -104,12 +177,12 @@ class PolygonModel {
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
|
|
||||||
size_t m_numVertices;
|
|
||||||
|
|
||||||
// both will hold 3 * numVertices floats
|
// both will hold 3 * numVertices floats
|
||||||
std::vector<float> m_data_position;
|
std::vector<float> m_data_position;
|
||||||
std::vector<float> m_data_normal;
|
std::vector<float> m_data_normal;
|
||||||
|
|
||||||
|
size_t m_numVertices;
|
||||||
|
|
||||||
GLuint m_vbo_id_position;
|
GLuint m_vbo_id_position;
|
||||||
GLuint m_vbo_id_normal;
|
GLuint m_vbo_id_normal;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,14 +9,19 @@ namespace endofthejedi {
|
||||||
{
|
{
|
||||||
std::cout<<"setup 3d" << std::endl;
|
std::cout<<"setup 3d" << std::endl;
|
||||||
|
|
||||||
PolygonModel atomicBomb("../data/mesh/small_atomic_bomb.stl");
|
m_atomicBomb = new PolygonModel("../data/mesh/small_atomic_bomb.stl");
|
||||||
exit(-1);
|
m_atomicBomb->loadIntoOpenGl();
|
||||||
|
|
||||||
|
m_models.push_back(m_atomicBomb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::render(const game::State *state)
|
void RendererPolygon3d::render(const game::State *state)
|
||||||
{
|
{
|
||||||
(void) state;
|
(void) state;
|
||||||
|
|
||||||
std::cout<<"render 3d" << std::endl;
|
m_atomicBomb->bind();
|
||||||
|
m_atomicBomb->render();
|
||||||
|
|
||||||
|
//std::cout<<"render 3d" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,5 +25,7 @@ namespace endofthejedi {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<PolygonModel*> m_models;
|
std::vector<PolygonModel*> m_models;
|
||||||
|
|
||||||
|
PolygonModel *m_atomicBomb;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue