Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid/openGL: fill a 2d viewport with a square
    text
    copied!<p>What I've managed to accomplish so far is:</p> <ul> <li>Initialise the GLSurfaceView/Renderer</li> <li>Draw a triangle on the screen</li> <li>Render a square/rectangle on the screen</li> <li>Add a bitmap texture to the screen</li> <li>Ensure PNG transparency is honoured when rendering</li> <li>Automatically scale the triangles so they show up correctly for all screen sizes</li> </ul> <p>However, after fixing the scaled triangles, the background rectangle (with texture) no longer fills up the screen.</p> <p><img src="https://i.stack.imgur.com/e4Fui.gif" alt="The background no longer fills up the screen"></p> <p>I've been stuck on this for a while now and absolutely baffled to the point I have thrown in the towel.</p> <p>The main parts I'm unsure about is the use of glFrustumf() and gluLookAt().</p> <pre><code>@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); ratio = (float) width / height; gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode gl.glLoadIdentity(); // reset the matrix to its default state gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); // apply the projection matrix } @Override public void onDrawFrame(GL10 gl) { // Clear the screen gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // Set GL_MODELVIEW transformation mode gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); // reset the matrix to its default state // When using GL_MODELVIEW, you must set the camera view GLU.gluLookAt(gl, 0, 0, -5f, 0f, 0f, 0f, 0.0f, 1.0f, 0.0f); bg.draw(gl); // ... } </code></pre> <p>If anybody has a moment to take a look at the problem, I've uploaded the files to <a href="https://bitbucket.org/koonkii/test_opengl/src" rel="nofollow noreferrer">https://bitbucket.org/koonkii/test_opengl/src</a> so you don't have to recreate the code by copy-pasting.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload