# Orthographic projection test - doesn't render

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

## Recommended Posts

Hi, I'm trying to create a basic 2D setup, using orthographic projection. I am trying to render a red triangle to screen, but the window is all black.

I can't figure out what's wrong, so it would be nice if someone could just look through my files for obvious errors. The main file uses some functions from glwrapper.cpp. I also have glwrapper.h which contains the function declarations for glwrapper.cpp, with the same signatures.

main.cpp:          http://hastebin.com/tejukifije.vala

glwrapper.cpp:  http://hastebin.com/odogiruviy.coffee

viewMatrix2D should return a matrix that just translates by center offset of camera.

ortho2D should give an orthographic projection matrix assuming that the viewing area is symmetric.

The vertex data is given in pixels, and the ortho2D matrix should correctly convert that to NCD given viewport width and height.

I also tried without any projection/view, and I tried giving the triangle position using normalized coordinates.

##### Share on other sites
I want to say your buffer data bind and vertex attribute pointer is at fault. I see you use a function to upload the data which is fine it looks good, but you are uploading data (triangleArray) that is GLint. Then in your VAO calls you are doing the vertex attribute call with float. There is a miss match here for sure. I think you'll be all good (with atleast getting that normalized triangle to show) if you make your triangleArry a GLFloat, keep the type for the pointer as GL_FLOAT, and change the size of the stride to: 2 * sizeof(GLFloat) Edited by noodleBowl

##### Share on other sites

Thanks for the reply!

Unfortunately, it still doesn't work. I have the following changes:

GLfloat triangleArray[] = {
0.0f, 8.0f,
-2.0f, -2.0f,
2.0f, -2.0f
};

[...]

setVertexAttribPointer(shaderProgram, "position", 2, GL_FLOAT, 2*sizeof(GLfloat), 0);


The  program compiles and runs without problems, but it's still only black. I did try with normalized triangle coordinates as well .

##### Share on other sites

You're not passing any data to your 'model' uniform matrix, so your gl_Position is ruined. Start from there, and just see where it goes next :)

##### Share on other sites

Thanks! It works now :)