I am trying to load a .obj file using a .obj file loader I built and it seems to be working correctly (in terms of loading).
With that being said, when I go to draw the 3d object to the screen it creates a large red square.
GLenum err = glewInit();
if (err != GLEW_OK)
{
std::cout << "NOT WORKING" << std::endl;
}
const char* vertexShaderSource = "#version 330\n\
in vec4 position;\
void main(void) {\
gl_Position = position;\
}";
// compile fragment shader source
const GLchar* fragmentShaderSource = "#version 330\n\
out vec4 fragColor;\
void main(void) {\
fragColor = vec4(1.0,0.3,0.3,0.15);\
}";
/* Creating Shader */
this->programId = glCreateProgram();
this->vId = glCreateShader(GL_VERTEX_SHADER);
this->fId = glCreateShader(GL_FRAGMENT_SHADER);
/* Get Shader Size */
int vertexShaderLength = strlen(vertexShaderSource);
int fragmentShaderLength = strlen(fragmentShaderSource);
/* Loading and binding shader */
glShaderSource(this->vId, 1, &vertexShaderSource, NULL);
glShaderSource(this->fId, 1, &fragmentShaderSource, NULL);
/* Compile Shaders */
glCompileShader(vId);
int iIsOk = 0;
glGetShaderiv(this->vId, GL_COMPILE_STATUS, &iIsOk);
if (!iIsOk)
{
return;
}
int iIsOk2;
glCompileShader(fId);
glGetShaderiv(this->fId, GL_COMPILE_STATUS, &iIsOk2);
if (!iIsOk2)
{
std::cout << "U SUCK!" << std::endl;
std::cout << glGetError() << std::endl;
}
/* Attach Shaders */
glAttachShader(this->programId, this->vId);
glAttachShader(this->programId, this->fId);
/* Bind Attributes from Shader */
glBindAttribLocation(this->programId, 0, "position");
glBindFragDataLocation(this->programId, 0, "fragcolor");
/* Link gprogram */
glLinkProgram(this->programId);
/* Use and bind attribute */
glUseProgram(this->programId);
this->positionId = glGetAttribLocation(this->programId, "position");
glUseProgram(0);
/* VAO Time */
glGenVertexArrays(1, &this->vaoId);
glBindVertexArray(this->vaoId);
/* VBO Time assigning to VAO */
glGenBuffers(1, &this->vboId);
glBindBuffer(GL_ARRAY_BUFFER, this->vboId);
glBufferData(GL_ARRAY_BUFFER, vertcies.size() * sizeof(sf::Vector3f), &vertcies[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(this->positionId);
glVertexAttribPointer(this->positionId, 3, GL_FLOAT, GL_FALSE, sizeof(sf::Vector3f), 0);
/* Close out bindings */
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
DRAW:
glUseProgram(this->programId);
glBindVertexArray(this->vaoId);
glDrawArrays(GL_TRIANGLES, 0, this->vertcies.size());
glBindVertexArray(0);
glUseProgram(0);
I uploaded an image of what the red box displayed.
I am curious if I am missing something in the openGL code or what I am doing wrong?
I am able to display a triangle correctly, but when I go to load my .obj files this is the stuff I get displayed.
The above is all the openGL code I have in the project, is there a simple error in my code...or forgetting something?