java - OpenGL not rendering as expected -
if have screen setup following
gl.glviewport(0,0,width,height); //reset current viewport gl.glmatrixmode(gl10.gl_projection); //select projection matrix gl.glloadidentity(); //reset projection matrix gl.glorthof(0f,1f,0f,1f,-1f,1f); and vertices set follows
this._vertices=new float[]{ 0.0f,0.5f,0.0f, //v1 bottom left 0.0f,1.0f,0.0f, //v2 top left 0.5f,0.5f,0.0f, //v3 bottom right 0.5f,1.0f,0.0f //v4 top right }; then when drawing do
gl.gltranslatef(0.0f,0.0f,0.0f); it places square in top left (i thought 0,0 bottom left?)
and then
gl.gltranslatef(0.5f,-0.5f,0.0f); places square in middle of screen (suggesting bottom -1.0f rather 0.0f)
how make bottom left of screen start 0,0?
update------
i have found if change line
gl.glorthof(0f,1f,0f,1f,-1f,1f); to
gl.glorthof(0f,1f,1f,0f,-1f,1f); then nothing changes (ie top left still 0,0 , bottom left 0,-1)
however if leave line out origin in centre of screen (ie top left -1,-1)
the glorthof used create screen coordinate system, since input parameters left, right, top , bottom can not understand confusion lies. if wish top left corner (0,0) point set top , left parameters 0 , bottom , right positive values positive x right , positive y downwards.
some common cases of usage of glorthof are:
- view coordinate system insert
(0,0)top-left ,(screenheight , screenwidth)bottom-right. in quite few cases bottom-left @(0,0)though. - graph coordinate system screen centre @
(0,0), top-left @(1,-1), bottom-right @(-1,1) - normalized view system has screen centre @
(0,0)height relative width depending on screen ratio. top-left @(-1,-(screenheight/screenwidth)), bottom-right @(1, screenheight/screenwidth).
you should note in 1st , 3rd cases square drawn square , not rectangle (where a/b = screenwidth/screenheight). choose suits application best.
you should know glorthof useful panning , zooming. instead of doing strange translations , scales can change glorthof parameters display part of scene.
Comments
Post a Comment