PDA

View Full Version : Not loading cube?



Rockinredross867
11-08-2015, 04:28 PM
I have been trying to load a cube, but it won't load.

main game loop


GLint projectionLoc = glGetUniformLocation(entityShader.shaderProgram, "projection");
GLint viewLoc = glGetUniformLocation(entityShader.shaderProgram, "view");
GLint modelLoc = glGetUniformLocation(entityShader.shaderProgram, "model");
GLint camPosLoc = glGetUniformLocation(entityShader.shaderProgram, "viewPos");

glm::mat4 projection;
projection = glm::perspective(camera.Zoom, (GLfloat) mainWindow.m_Width / mainWindow.m_Height, 0.1f, 100.0f);

glm::mat4 view;
view = camera.GetViewMatrix();

glm::mat4 model;
model = glm::translate(model, glm::vec3(1.0f, 1.0f, 1.0f));

entityShader.enable();
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glUniform3f(camPosLoc, camera.Position.x, camera.Position.y, camera.Position.z);
mainLight.loadLight(entityShader);
boxMaterial.applyMaterial(entityShader);
glBindVertexArray(renderer.VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);

material.cpp


#include "material.h"

namespace sde {
namespace graphics {
Material::Material(GLfloat shininess, glm::vec3 ambient, GLint diffuseMap, GLint specularMap, GLuint diffTexture, GLuint specTexture) :
m_Shininess(shininess), m_Ambient(ambient), m_DiffuseMap(diffuseMap), m_SpecularMap(specularMap), m_DiffTexture(diffTexture), m_SpecTexture(specTexture)
{
}

void Material::applyMaterial(sde::shaders::ShaderProgra m shaders) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_DiffTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_SpecTexture);

glUniform1f(glGetUniformLocation(shaders.shaderPro gram, "material.shininess"), m_Shininess);
glUniform3f(glGetUniformLocation(shaders.shaderPro gram, "material.ambient"), m_Ambient.r, m_Ambient.g, m_Ambient.b);
glUniform1i(glGetUniformLocation(shaders.shaderPro gram, "material.diffuseMap"), m_DiffuseMap);
glUniform1i(glGetUniformLocation(shaders.shaderPro gram, "material.specularMap"), m_SpecularMap);
}
}
}

light.cpp


#include "light.h"

namespace sde {
namespace gameobject {

Light::Light(glm::vec3 lightPos, glm::vec3 ambient, glm::vec3 diffuse, glm::vec3 specular) :
m_LightPos(lightPos), m_Ambient(ambient), m_Diffuse(diffuse), m_Specular(specular)
{
}

void Light::loadLight(sde::shaders::ShaderProgram shaders) {
glUniform3f(glGetUniformLocation(shaders.shaderPro gram, "light.direction"), m_LightPos.x, m_LightPos.y, m_LightPos.z);
glUniform3f(glGetUniformLocation(shaders.shaderPro gram, "light.ambient"), m_Ambient.r, m_Ambient.g, m_Ambient.b);
glUniform3f(glGetUniformLocation(shaders.shaderPro gram, "light.diffuse"), m_Diffuse.r, m_Diffuse.g, m_Diffuse.b);
glUniform3f(glGetUniformLocation(shaders.shaderPro gram, "light.specular"), m_Specular.r, m_Specular.g, m_Specular.b);
}

}
}

renderer.cpp


glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);

glGenBuffers(1, &VBO);
//glGenBuffers(1, &EBO);

//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);

//glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);

glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);

glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLfloat*)(6 * sizeof(GLfloat)));
glEnableVertexAttribArray(2);

glBindVertexArray(0);