Sign in to follow this  

Orthographic projection test - doesn't render

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.




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.


Thanks in advance!

Share this post

Link to post
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 this post

Link to post
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 this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this