Skip to content

Commit

Permalink
Being off by one in your ortho projection...
Browse files Browse the repository at this point in the history
has strange effects.  See

https://github.com/rswinkle/opengl_reference/blob/master/src/multidraw2.cpp

Only the right/upper half of the squares move, but the interpolation
within the squares is affected, though less and less as you get closer
to the screen space origin (ie lower left).
  • Loading branch information
rswinkle committed Jun 2, 2024
1 parent b6b8703 commit 54c3c34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions demos/multidraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ typedef struct My_Uniforms

int polygon_mode;
int use_elements;
int minus_1;
matrix_stack mat_stack;
My_Uniforms the_uniforms;

void cleanup();
Expand Down Expand Up @@ -108,9 +110,7 @@ int main(int argc, char** argv)
glUseProgram(program);
pglSetUniform(&the_uniforms);

matrix_stack mat_stack;
//rsw::make_perspective_matrix(mat_stack.stack[mat_stack.top], DEG_TO_RAD(45), WIDTH/(float)HEIGHT, 0.1f, 100.0f);
rsw::make_orthographic_matrix(mat_stack.stack[mat_stack.top], 0, WIDTH-1, 0, HEIGHT-1, 1, -1);
rsw::make_orthographic_matrix(mat_stack.stack[mat_stack.top], 0, WIDTH, 0, HEIGHT, 1, -1);


unsigned int old_time = 0, new_time=0, counter = 0;
Expand Down Expand Up @@ -237,7 +237,17 @@ int handle_events()
} else {
puts("Using MultiDrawArrays");
}
} else if (sc == SDL_SCANCODE_M) {
minus_1 = !minus_1;
if (minus_1) {
puts("minus_1");
rsw::make_orthographic_matrix(mat_stack.stack[mat_stack.top], 0, WIDTH-1, 0, HEIGHT-1, 1, -1);
} else {
puts("all the pixels");
rsw::make_orthographic_matrix(mat_stack.stack[mat_stack.top], 0, WIDTH, 0, HEIGHT, 1, -1);
}
}

}
}
return 0;
Expand Down
1 change: 1 addition & 0 deletions testing/multidraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void test_multidraw(int argc, char** argv, void* data)
pgl_uniforms the_uniforms;
pglSetUniform(&the_uniforms);

// TODO This shouldn't be WIDTH-1, HEIGHT-1, will have to update expected output
make_orthographic_matrix(the_uniforms.mvp_mat, 0, WIDTH-1, 0, HEIGHT-1, 1, -1);

glClear(GL_COLOR_BUFFER_BIT);
Expand Down

0 comments on commit 54c3c34

Please sign in to comment.