Jump to content
  • Advertisement
Sign in to follow this  

OpenGL OpenGL 4 viewing problem

This topic is 2461 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 currently trying to setup the viewing in a small OpenGL4 program.
I use the glm library for the matrix/vector calculations.

My problem is that the viewing seems to be messed up and i haven't been able to find out why.

You can find an image of the "broken" result here: http://imgur.com/NhPqF

My code looks like this:

VertexArray* dataVa;
VertexBufferObject* positionVbo;
VertexBufferObject* colorVbo;
glm::mat4 p, v;

void init() {
if (glewInit() != GLEW_OK) {
emit debug("Failed to init glew");


void initView() {
p = glm::perspective(45.0, 1.0, 1.0, 100.0);
v = glm::lookAt(glm::vec3(0.0, 0.0, 10.0), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));

void initData() {
int dataSize = 9;
float positionData[] = { -0.8f, -0.8f, 0.0f, 0.8f, -0.8f, 0.0f, 0.0f, 0.8f, 0.0f };
positionVbo = new VertexBufferObject;
positionVbo->setData(positionData, dataSize);

float colorData[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f };
colorVbo = new VertexBufferObject;
colorVbo->setData(colorData, dataSize);

dataVa = new VertexArray;
dataVa->setData(positionVbo->id(), 0, 3);

dataVa->setData(colorVbo->id(), 1, 3);

void initShader() {
shaderProgram = new ShaderProgram;
QString msg;
msg = shaderProgram->
emit debug(msg + " (vertex)");

msg = shaderProgram->
emit debug(msg + " (fragment)");

shaderProgram->createVariable(0, "VertexPosition");
shaderProgram->createVariable(1, "VertexColor");

QString linkMsg = shaderProgram->getLinkStatus();
emit debug(linkMsg);

void initializeGL() {
glClearColor(0.0, 0.0, 0.0, 0.0);

void resizeGL(int width, int height) {
glViewport(0, 0, width, height);

void paintGL() {
shaderProgram->createUniformMat4(&v[0][0], "View");
shaderProgram->createUniformMat4(&p[0][0], "Proj");
dataVa->draw(GL_TRIANGLES, 0, 3);

My shaders look like this:

Vertex Shader:

#version 400

in vec3 VertexPosition;
in vec3 VertexColor;

out vec3 Color;

uniform mat4 View;
uniform mat4 Proj;

void main()
Color = VertexColor;
gl_Position = Proj * View * vec4(VertexPosition, 1.0);

Fragment Shader:

#version 400

in vec3 Color;
out vec4 FragColor;

void main() {
FragColor = vec4(Color, 1.0);

Thanks in advance.

EDIT: The correct result should look more like this: http://imgur.com/Pfpyh
The correct triangle was rendered via immediate mode, please ignore the messages in the log widget.

Share this post

Link to post
Share on other sites
I have fixed the problem. The root cause of the problem was the draw method, the viewing is correct.

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!