opengl - glOrtho appears to have no effect -



opengl - glOrtho appears to have no effect -

i drawing square coordinates (-.5, -.5), (-.5, .5), (.5, .5), (.5, -.5) , noticed appeared squashed in 800 x 600 window (which seems exclusively logical).

i trying prepare square appeared square, not rectangular. approach phone call glortho() values of left = -ar, right = ar, bottom = -1, top = 1 ar aspect ratio (800/600). found phone call made glortho() had no effect, including 1 making (i remove , nil change).

my understanding of glortho() maps corners of opengl context values supplied, , stretches between points fit. incorrect, or doing that's preventing phone call glortho() taking effect?

class="lang-java prettyprint-override">import org.lwjgl.bufferutils; import org.lwjgl.lwjglexception; import org.lwjgl.opengl.display; import org.lwjgl.opengl.displaymode; import java.nio.floatbuffer; import static org.lwjgl.opengl.gl11.*; import static org.lwjgl.opengl.gl15.*; public class glorthotestdriver { public static void main(string[] args) { seek { display.setdisplaymode(new displaymode(800, 600)); display.settitle("glortho test"); display.create(); } grab (lwjglexception e) { e.printstacktrace(); display.destroy(); system.exit(1); } // initialization code opengl glmatrixmode(gl_projection); glortho(-1, 1, -1, 1, -1, 1); glloadidentity(); // scene setup int vertexbufferhandle; int colorbufferhandle; floatbuffer vertexdata = bufferutils.createfloatbuffer(8); vertexdata.put(new float[] { -.5f, -.5f, -.5f, .5f, .5f, .5f, .5f, -.5f } ); vertexdata.flip(); floatbuffer colordata = bufferutils.createfloatbuffer(12); colordata.put(new float[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ); colordata.flip(); vertexbufferhandle = glgenbuffers(); colorbufferhandle = glgenbuffers(); glbindbuffer(gl_array_buffer, vertexbufferhandle); glbufferdata(gl_array_buffer, vertexdata, gl_static_draw); glbindbuffer(gl_array_buffer, colorbufferhandle); glbufferdata(gl_array_buffer, colordata, gl_static_draw); glbindbuffer(gl_array_buffer, 0); while (!display.iscloserequested()) { glclear(gl_color_buffer_bit); glbindbuffer(gl_array_buffer, vertexbufferhandle); glvertexpointer(2, gl_float, 0, 0); glbindbuffer(gl_array_buffer, colorbufferhandle); glcolorpointer(3, gl_float, 0, 0); glenableclientstate(gl_vertex_array); glenableclientstate(gl_color_array); gldrawarrays(gl_quads, 0, 4); gldisableclientstate(gl_color_array); gldisableclientstate(gl_vertex_array); display.update(); display.sync(60); } gldeletebuffers(vertexbufferhandle); gldeletebuffers(colorbufferhandle); display.destroy(); } }

ah - problem you're calling glloadidentity after calling glortho. glloadidentity replaces matrix in current mode (gl_projection) identity matrix, wiping out previous phone call glortho.

try calling glloadidentity before glortho.

opengl

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -