Skip to content

Commit

Permalink
Added debugging component to lab with verifyVAO
Browse files Browse the repository at this point in the history
  • Loading branch information
kazar4 committed Sep 2, 2023
1 parent 8389037 commit b53474a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/glrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ void GLRenderer::initializeGL()

// Task 13: Add position and color attributes to your VAO here

// Task 13: Verify your position and color attributes with our verifyVAO function

// Copy over your attributes from glVertexAttribPointer() to verifyVAO
// So the following function becomes:
// glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4, reinterpret_cast<void*>(0));
// verifyVAO(triangleData, 0, 2, 4, reinterpret_cast<void*>(0));
// If the function prints the values you would expect for position and color then you're good!

//std::cout << "Position Values" << std::endl;
//verifyVAO();
//std::cout << "Color Values" << std::endl;
//verifyVAO();

// ================== Returning to Default State

// Task 14: Unbind your VBO and VAO here
Expand Down
22 changes: 22 additions & 0 deletions src/glrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "GL/glew.h" // Must always be first include
#include <QOpenGLWidget>
#include "glm/glm.hpp"
#include <iostream>

class GLRenderer : public QOpenGLWidget
{
Expand All @@ -24,4 +25,25 @@ class GLRenderer : public QOpenGLWidget
GLuint m_shader; // Stores id of shader program
GLuint m_vbo; // Stores id of VBO
GLuint m_vao; // Stores id of VAO

void verifyVAO(std::vector<GLfloat> triangleData, GLuint index, GLsizei size, GLsizei stride, const void* offset) {

int newStride = int(stride / 4);
int groupNum = 0;
int newOffset = static_cast<int>(reinterpret_cast<intptr_t>(offset)) / 4;

for (int i = newOffset; i < triangleData.size(); i = i + newStride) {
std::cout << "Group " << groupNum << " of Values for VAO index " << index << std::endl;
std::cout << "[";
for (auto j = i; j < i + size; ++j) {
if (j != i + size - 1) {
std::cout << triangleData[j]<< ", ";
} else {
std::cout << triangleData[j]<< "]" << std::endl;
}
}
groupNum = groupNum + 1;
}
std::cout << "" << std::endl;
}
};

0 comments on commit b53474a

Please sign in to comment.