-2

I am trying to have one of the viewports in my window display an orthographic projection of a teapot.

mat4 view = translate (identity_mat4 (), vec3 (0.0, 0.0, -40.0));
mat4 persp_proj = perspective(50.0, (float)width/(float)height, 0.1, 100.0);
mat4 model = rotate_x_deg (identity_mat4 (), 40);
glViewport (0, 0, width / 2, height / 2);
glOrtho(0,400,0,300,0,1);
    glUniformMatrix4fv (proj_mat_location, 1, GL_FALSE, persp_proj.m);
glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view.m);
glUniformMatrix4fv (matrix_location, 1, GL_FALSE, model.m);
glDrawArrays (GL_TRIANGLES, 0, teapot_vertex_count);

This is the part in the code that I would like to use glOrtho to draw an orthographic view of the teapot. First of all, am I even using glOrtho correctly? I think I am, but I'm not getting what I hopped to get so I'm doubt I am.

Why doesn't what I have work, and how I would go about fixing it?

If I am supposed to put glOrtho in a specific place it would be helpful to know where.

Also, as I am supposed to have several viewports will all of the viewports have an orthographic projection after that?

Here's my entire program code snipet is taken from lines 192-204

genpfault
  • 51,148
  • 11
  • 85
  • 139
mcdowesj
  • 48
  • 6
  • You appear to be getting mixed up between shaders and the fixed function pipeline. It makes no sense to use glOrtho and also glUniformMatrix4fv. It also makes no sense to apply a perspective projection and an orthographic projection, you want one or the other. – Eric B Oct 17 '13 at 21:28
  • Of course it is not. `glOrtho (...)` multiplies the "current" matrix by an orthographic projection matrix. Since you are using shaders with their own matrix uniforms, the notion of a "current" matrix makes no sense. Not to mention in a GL3 core context, there is no matrix stack, so `glOrtho (...)` is an invalid function. – Andon M. Coleman Oct 17 '13 at 21:28
  • -1, *complete* code goes *in* the question, not on a pastebin. – genpfault Oct 17 '13 at 21:30
  • Thanks guys. As I said, I'm new to this so I'm trying to learn as much as I can as I go along. Cheers – mcdowesj Oct 17 '13 at 21:31

1 Answers1

2

I don't have full knowledge of your program, but given what I see, I doubt glOrtho will work at all. It is a (deprecated) function used to multiply the current matrix in the fixed function pipeline by an orthographic projection matrix. However, your program appears to use shaders and construct its own matrices (as a modern OpenGL program should). So if what you currently have sans glOrtho works, what you really need to do is replace your mat4 persp_proj with a mat4 ortho_proj that contains the orthographic projection you want.

Eric B
  • 4,367
  • 5
  • 33
  • 43