2D rendering (matrices, specifically) in OpenGL ES 2.0 (Android) -
so i'm trying render 2 moving quads, each @ different locations. shaders simple possible (vertices transformed modelview-projection matrix, there's 1 color).
whenever try , render something, end slivers of color! i've done work 3d rendering in opengl before i'm having issues 2d stuff.
here's basic rendering loop, simplified bit (i'm using matrix manipulation methods provided android.opengl.matrix
, program
custom class created calls gles20.gluniformmatrix4fv()
):
matrix.orthom(projection, 0, 0, windowwidth, 0, windowheight, -1, 1); program.setuniformmatrix4f("projection", projection);
at point, render quads (this repeated each quad):
matrix.setidentitym(modelview, 0); matrix.translatem(modelview, 0, quadx, quady, 0); program.setuniformmatrix4f("modelview", modelview); quad.render(); // calls gldrawarrays
and see sliver of color each quad is! i'm @ wits end here, i've tried can think of , i'm @ point i'm screaming @ computer , tossing phones across room. got pointers? using ortho wrong? i'm 100% sure i'm rendering @ z value of 0. tried using frustumm
instead of orthom
, made see quads totally skewed whenever got moved, makes sense if correctly understand way frustum works (it's more 3d rendering, anyway).
if makes difference, defined viewport with
gles20.glviewport(0, 0, windowwidth, windowheight);
where windowwidth
, windowheight
same values pased orthom
edit: might worth noting android.opengl.matrix
methods take in offset second parameter multiple matrices can shoved 1 array, that'w first 0
for
another edit: reference, here's vertex shader code:
uniform mat4 modelview; uniform mat4 projection; attribute vec4 vposition; void main() { mat4 mvp = projection * modelview; gl_position = vposition * mvp; }
yet edit: tried swapping projection * modelview
modelview * projection
funky looking shapes...
mvp should proj*modelview have it.
gl_position should mvp * vposition, not other way around show in code there.
if not solve problem, can better describe problem (an image might help)? consider posting more of opengl code, in case error there. rest of code posted looks fine me.
Comments
Post a Comment