Skip to content

Commit de9e0b8

Browse files
committed
Texture fixes
1 parent 538d0c8 commit de9e0b8

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

GUI/OpenGL/MiniGL.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ VectorXf MiniGL::m_lightPosition;
8484
GLuint MiniGL::m_vao = 0;
8585
GLuint MiniGL::m_vbo_vertices = 0;
8686
GLuint MiniGL::m_vbo_normals = 0;
87+
GLuint MiniGL::m_vbo_texcoords = 0;
8788
GLuint MiniGL::m_vbo_faces = 0;
8889

8990
void MiniGL::bindTexture()
@@ -519,6 +520,7 @@ void MiniGL::init(const int width, const int height, const char *name, const boo
519520
glBindVertexArray(m_vao);
520521
glGenBuffers(1, &m_vbo_vertices);
521522
glGenBuffers(1, &m_vbo_normals);
523+
glGenBuffers(1, &m_vbo_texcoords);
522524
glGenBuffers(1, &m_vbo_faces);
523525
// Set the default normal (cf. glNormal).
524526
glVertexAttrib3r(1, 0.0, 0.0, 1.0);
@@ -547,7 +549,7 @@ void MiniGL::initTexture()
547549

548550
glGenTextures(1, &m_texId);
549551
glBindTexture(GL_TEXTURE_2D, m_texId);
550-
glTexImage2D(GL_TEXTURE_2D, 0, 3, IMAGE_COLS, IMAGE_ROWS, 0, GL_RGB,
552+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, IMAGE_COLS, IMAGE_ROWS, 0, GL_RGB,
551553
GL_UNSIGNED_BYTE, texData); // Create texture from image data
552554
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
553555
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -574,6 +576,7 @@ void MiniGL::destroy ()
574576
{
575577
glDeleteBuffers(1, &m_vbo_vertices);
576578
glDeleteBuffers(1, &m_vbo_normals);
579+
glDeleteBuffers(1, &m_vbo_texcoords);
577580
glDeleteBuffers(1, &m_vbo_faces);
578581
glDeleteVertexArrays(1, &m_vao);
579582
}

GUI/OpenGL/MiniGL.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ namespace SPH
125125
static GLuint m_vao;
126126
static GLuint m_vbo_vertices;
127127
static GLuint m_vbo_normals;
128+
static GLuint m_vbo_texcoords;
128129
static GLuint m_vbo_faces;
129130

130131
static void reshape (GLFWwindow* glfw_window, int w, int h);
@@ -237,6 +238,7 @@ namespace SPH
237238
static const GLuint getVao() { return m_vao; }
238239
static const GLuint getVboVertices() { return m_vbo_vertices; }
239240
static const GLuint getVboNormals() { return m_vbo_normals; }
241+
static const GLuint getVboTexcoords() { return m_vbo_texcoords; }
240242
static const GLuint getVboFaces() { return m_vbo_faces; }
241243

242244
// Fill a VBO with vector data and map to the VAO attribute at the specified index.
@@ -254,6 +256,12 @@ namespace SPH
254256
{
255257
supplyVectors(index, m_vbo_normals, 3, numVectors, data);
256258
}
259+
// Fill the dedicated VBO with 2D texcoord data and map to the VAO attribute at the specified index.
260+
template<typename T>
261+
static void supplyTexcoords(GLuint index, unsigned int numVectors, const T* data)
262+
{
263+
supplyVectors(index, m_vbo_texcoords, 2, numVectors, data);
264+
}
257265
// Fill a VBO with index data.
258266
static void supplyIndices(GLuint vbo, unsigned int n, const unsigned int* data);
259267
// Fill the dedicated VBO with face index data.

Simulator/PositionBasedDynamicsWrapper/PBD_Simulator_GUI_imgui.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ namespace SPH
7272
const unsigned int nFaces = mesh.numFaces();
7373
const Vector3r *vertexNormals = mesh.getVertexNormals().data();
7474

75-
SPH::MiniGL::supplyVertices(0, mesh.getVertexNormals().size(), &pd.getPosition(offset)[0]);
76-
SPH::MiniGL::supplyNormals(2, mesh.getVertexNormals().size(), &vertexNormals[0][0]);
75+
SPH::MiniGL::supplyVertices(0, mesh.numVertices(), &pd.getPosition(offset)[0]);
76+
SPH::MiniGL::supplyNormals(2, mesh.numVertices(), &vertexNormals[0][0]);
7777
SPH::MiniGL::supplyFaces(3 * nFaces, faces);
7878

7979
glDrawElements(GL_TRIANGLES, (GLsizei)3 * nFaces, GL_UNSIGNED_INT, (void*)0);

0 commit comments

Comments
 (0)