Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling glTexImage2D clears data buffer
    primarykey
    data
    text
    <p>I'm using LWJGL for its OpenGL bindings and I'm trying to draw a quad with a texture. I have done so successfully, but there is a strange side-effect and I'm unsure why it's presenting itself. </p> <p>The following code executes when first loading the texture (before the first render). I save the value of <code>textureID</code> for when I bind the texture/draw the quad. The following set-up code is taken from an SO answer found <a href="https://stackoverflow.com/questions/10801016/lwjgl-textures-and-strings">here</a>. </p> <pre><code>int textureID = GL11.glGenTextures(); // Generate texture ID GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); // Bind texture ID // Setup wrap mode GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); // Setup texture scaling filtering GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); // Send texel data to OpenGL GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); </code></pre> <p>In the rendering loop, I draw the quad with the following code:</p> <pre><code>int texture = TextureLoader.loadTexture(TextureLoader.loadImage("/pc_run/run3.png")); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glBegin(GL11.GL_QUADS); { GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex2f(-hw, -hh); GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex2f(+hw, -hh); GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex2f(+hw, +hh); GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex2f(-hw, +hh); } GL11.glEnd(); </code></pre> <p>So far, this works (and is also wrapped between <code>glPushMatrix()</code>/<code>glPopMatrix()</code> calls). However, whatever I have drawn to the GLContext so far is not displayed. Removing the call to <code>GL11.glTexImage2D</code> in the initialization code, the sprite is not displayed, but everything else (non-textured) is displayed correctly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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