Note that there are some explanatory texts on larger screens.

plurals
  1. POTexture size when using JOGL
    primarykey
    data
    text
    <p>In my next project, I'm trying to learn JOGL. The result should be a simple 2d animation.</p> <p>I've heard, that a texture must be 2^n*2^n in size. Can I still use images which don't have this size, or do I have to edit all images in advance? What do I have to take care of, when using such textures?</p> <p>As an example, I want to show a kind of progress bar, whose image is at the size of 1024*96px. Do I have to define a quad (eg.1024*1024 in size if you calculate the pixels) and use alpha blending to show only the "filled" part? Or are texture coordinates the way to go?</p> <p>[Edit] Works, solution looks like this (using orthogonal projection):</p> <pre><code>@Override public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); // get GL glu = new GLU(); //... t = load(".\\TEXTURES\\ProgressBarBG.png"); //... } public Texture load(String fileName){ Texture text = null; try{ text = TextureIO.newTexture(new File(fileName), false); text.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); text.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); }catch(Exception e){ System.out.println(e.getMessage()); System.out.println("Error loading texture " + fileName); } return text; } private void drawProgressBG(GL gl, int z) { gl.glPushMatrix(); gl.glLoadIdentity(); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL.GL_ALPHA_TEST); gl.glAlphaFunc(GL.GL_GREATER, 0); // only render if alpha &gt; 0 // don't show source alpha parts in the destination gl.glEnable(GL.GL_TEXTURE_2D); TextureCoords tc = t.getImageTexCoords(); t.enable(); t.bind(); gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(tc.left(), tc.bottom()); gl.glVertex3f( 0f, 0f, z); gl.glTexCoord2f(tc.right(), tc.bottom()); gl.glVertex3f( 1024f, 0f, z); gl.glTexCoord2f(tc.right(), tc.top()); gl.glVertex3f( 1024f, 96f, z); gl.glTexCoord2f(tc.left(), tc.top()); gl.glVertex3f( 0f, 96f, z); gl.glEnd(); gl.glDisable(GL.GL_TEXTURE_2D); // switch back to modulation of quad colours and texture gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); gl.glDisable(GL.GL_ALPHA); // switch off transparency gl.glDisable(GL.GL_BLEND); gl.glPopMatrix(); } </code></pre> <p>[/EDIT]</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.
    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