Jump to content
  • Advertisement
Sign in to follow this  

OpenGL OpenGL3.3 Not getting any colors

This topic is 2795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am pulling my hairs out with this one, not sure what I am doing wrong.
Using 2 simple shaders, compile and links correctly.


#version 330 core
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
out vec4 outColor;

void main()
gl_Position = vec4(inPosition.xyz, 1.0);
outColor = vec4(inColor, 1.0);


#version 330
out vec4 outFragColor;
in vec4 inColor;

void main()
outFragColor = inColor;

ArrayBuffer class header
#include <GL/glew.h>
// representing a openGL buffer object
class ArrayBufferObject
ArrayBufferObject(): mID(0){}
~ArrayBufferObject() {}
// create the buffer
void Create(float T[], GLenum usage)
// generate buffer
glGenBuffers(1, &mID);
glBindBuffer(GL_ARRAY_BUFFER, mID);
// fill with data
int byteSize = sizeof(float) * 18;
glBufferData(GL_ARRAY_BUFFER, byteSize, T, usage);
// unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);
// dispose of the buffer
void Dispose()
// unbind buffer and delete
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &mID);
void Bind() { glBindBuffer(GL_ARRAY_BUFFER, mID); }
void Unbind() { glBindBuffer(GL_ARRAY_BUFFER, 0); }
unsigned int GetID() { return mID; }
GLuint mID;

Draw code
// clear buffers
// use program
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)36);

glDrawArrays(GL_TRIANGLES, 0, 3);
// swap the buffers

Share this post

Link to post
Share on other sites
This is it, I am using a forward compatible core context.

float mPolygon[] =
-0.8f, -0.8f, 0.0f,
0.8f, -0.8f, 0.0f,
0.0f, 0.8f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
// create buffer for the triangle
PVB.Create(mPolygon, GL_STATIC_DRAW);

Share this post

Link to post
Share on other sites
Oh, just noticed. Variables between shaders are linked by their name. Your outColor in the vertex shader is not the same as the inColor in the pixel shader. Thus, you are writing to an unused output variable, and reading from an uninitialized input variable. They must have the same name if you want to link them together.

Share this post

Link to post
Share on other sites
Thank you so much it worked!! I haven't read a tutorial that said this piece of information!
Glad I asked here.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!