textures[i].bind(gl2); textures[i].enable(gl2); gl2.glPushMatrix(); gl2.glTranslatef((float)(width/2), (float)(height/2), 0); gl2.glEnd(); gl2.glPopMatrix(); textures[i].disable(gl2); textures[i].bind(gl2); textures[i].enable(gl2); gl2.glPushMatrix(); gl2.glTranslatef((float)(width/2), (float)(height/2), 0); gl2.glEnd(); gl2.glPopMatrix(); textures[i].disable(gl2); texYantra.bind(gl2); texYantra.enable(gl2); gl2.glPushMatrix(); gl2.glTranslatef((float)(width/2), (float)(height/2), 0); texYantra.bind(gl2); texYantra.enable(gl2); gl2.glPushMatrix(); gl2.glTranslatef((float)(width/2), (float)(height/2), 0); gl2.glEnd();
/** A GL2 context MUST be current. */ @Override public void mount(GL gl) { try { load(gl, image); } catch (Exception e) { throw new RuntimeException(e); } coords = texture.getImageTexCoords(); halfWidth = texture.getWidth() / 2; halfHeight = texture.getHeight() / 2; }
public void destroy(final GL gl) throws GLException { for(int i=frames.size()-1; i>=0; i--) { frames.get(i).getTexture().destroy(gl); } frames.clear(); }
private void bindTexture(Texture tex, int glType) { assert (tex != null); assert (currdraw == id); boolean size = checkSize(tex.getWidth(), tex.getHeight()); assert (size); assert ((tex.getTarget() == GL.GL_TEXTURE_2D || tex.getTarget() == GL2GL3.GL_TEXTURE_RECTANGLE)); assert (id != 0); gc.getGL().glFramebufferTexture2D(GL.GL_FRAMEBUFFER, glType, GL.GL_TEXTURE_2D, tex.getTextureObject(null), 0); }
private void renderFace(GL2 gl, Texture t) { TextureCoords tc = t.getImageTexCoords(); float tx1 = tc.left(); float ty1 = tc.top(); float tx2 = tc.right(); float ty2 = tc.bottom(); t.enable(gl); t.bind(gl); if (button==4) gl.glColor4f(0.8f, 0.2f, 0.2f, alpha); else gl.glColor4f(alpha, alpha, alpha, alpha); gl.glBegin(GL2.GL_QUADS); gl.glTexCoord2f(tx1, ty1); gl.glVertex2f(currentRect.x, currentRect.y); gl.glTexCoord2f(tx2, ty1); gl.glVertex2f(currentRect.x, currentRect.y + currentRect.height); gl.glTexCoord2f(tx2, ty2); gl.glVertex2f(currentRect.x + currentRect.width, currentRect.y + currentRect.height); gl.glTexCoord2f(tx1, ty2); gl.glVertex2f(currentRect.x + currentRect.width, currentRect.y); gl.glEnd(); t.disable(gl); }
private Texture setupTexture(GL2 gl, Texture texture, Group group) { if (group.getMaterial() != null) { texture = loadTexture(group); } if (texture != null && drawTexture) { gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Use linear filter for texture if image is smaller than the original texture gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_DECAL); texture.enable(gl); texture.bind(gl); } else { setupColor(gl); } return texture; }
/** * Sets the OpenGL multi-floating-point texture parameter for the * texture's target. Causes this texture to be bound to the current * texture state. * * @throws GLException if any OpenGL-related errors occurred */ public void setTexParameterfv(final GL gl, final int parameterName, final float[] params, final int params_offset) { bind(gl); gl.glTexParameterfv(target, parameterName, params, params_offset); }
final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); final Texture tex = frame.getTexture(); final TextureCoords tc = tex.getImageTexCoords(); final float tcSx = 1f / ( tc.right() - tc.left() ); colorTexBBox[0] = box.getMinX() * tcSx; colorTexBBox[2] = box.getMaxX() * tcSx; final float tcSy; if( tex.getMustFlipVertically() ) { tcSy = 1f / ( tc.bottom() - tc.top() ); colorTexBBox[1] = box.getMaxY() * tcSy;
gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); final Texture texture = getTexture(); texture.enable(gl); texture.bind(gl); gl.glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_MODULATE); smoothingChanged = false; if (smoothing) { texture.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); if (mipmap) { texture.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR); } else { texture.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); texture.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); texture.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
/** * Bind texture. * * @param gl * context * @param texture * the texture */ public void bindTexture(GL2 gl, Texture texture) { // switch to texture mode and push a new matrix on the stack gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); // check to see if the texture needs flipping if (texture.getMustFlipVertically()) { gl.glScaled(1, -1, 1); gl.glTranslated(0, -1, 0); } // switch to modelview matrix and push a new matrix on the stack gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glPushMatrix(); // This is required to repeat textures gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); // enable, bind texture.enable(gl); texture.bind(gl); }
/** * Updates a subregion of the content area of this texture using the * given data. If automatic mipmap generation is in use (see {@link * #isUsingAutoMipmapGeneration isUsingAutoMipmapGeneration}), * updates to the base (level 0) mipmap will cause the lower-level * mipmaps to be regenerated, and updates to other mipmap levels * will be ignored. Otherwise, if automatic mipmap generation is not * in use, only updates the specified mipmap level and does not * re-generate mipmaps if they were originally produced or loaded. * * @param data the image data to be uploaded to this texture * @param mipmapLevel the mipmap level of the texture to set. If * this is non-zero and the TextureData contains mipmap data, the * appropriate mipmap level will be selected. * @param x the x offset (in pixels) relative to the lower-left corner * of this texture * @param y the y offset (in pixels) relative to the lower-left corner * of this texture * * @throws GLException if any OpenGL-related errors occurred */ public void updateSubImage(final GL gl, final TextureData data, final int mipmapLevel, final int x, final int y) throws GLException { if (usingAutoMipmapGeneration && mipmapLevel != 0) { // When we're using mipmap generation via GL_GENERATE_MIPMAP, we // don't need to update other mipmap levels return; } bind(gl); updateSubImageImpl(gl, data, target, mipmapLevel, x, y, 0, 0, data.getWidth(), data.getHeight()); }
public void draw( GL2ES3 gl, Texture texture, GLEditableBuffer stBuffer, GLEditableBuffer xyBuffer, int first, int count ) { if ( texture.getTarget( ) != GL_TEXTURE_2D ) { throw new RuntimeException( "Texture has wrong target: required = GL_TEXTURE_2D, found = " + texture.getTarget( ) ); } gl.glActiveTexture( GL_TEXTURE0 ); texture.bind( gl ); gl.glUniform1i( this.handles.IMAGE, 0 ); gl.glBindBuffer( GL_ARRAY_BUFFER, stBuffer.deviceBuffer( gl ) ); gl.glVertexAttribPointer( this.handles.inSt, 2, GL_FLOAT, false, 0, 0 ); gl.glBindBuffer( GL_ARRAY_BUFFER, xyBuffer.deviceBuffer( gl ) ); gl.glVertexAttribPointer( this.handles.inXy, 2, GL_FLOAT, false, 0, 0 ); gl.glDrawArrays( GL_TRIANGLE_STRIP, first, count ); }
private void disableTexture(GL2 gl, Texture texture) { //TODO make it better if (texture != null) { if (drawTexture) { texture.disable(gl); } texture = null; } }
BufferedImage image = paintComponentToImage( this.label ); TextureData textureData = newTextureData( gl.getGLProfile( ), image, false ); this.texture.updateImage( gl, textureData ); TextureCoords textureCoords = this.texture.getImageTexCoords( ); float texTop = textureCoords.top( ); float texLeft = textureCoords.left( ); int w_PX = this.texture.getImageWidth( ); int h_PX = this.texture.getImageHeight( );
if (mustReallocateTexture) { if (texture != null) { texture.destroy(gl); texture = null; if (mipmap && !texture.isUsingAutoMipmapGeneration()) { texture.destroy(gl); mipmap = false; textureData.setMipmap(false); texture.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); texture.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
readTexture.updateImage(gl, readTextureData); } else { readTexture.updateSubImage(gl, readTextureData, 0, 0, 0, // src offset 0, 0, // dst offset
public Texture(final GL gl, final TextureData data) throws GLException { this.texID = 0; this.target = 0; this.imageTarget = 0; updateImage(gl, data); }
/** * @param gl * @param texture */ public void setupFilter(GL gl, Texture texture) { if (filter) { // GL_LINEAR / GL_LINEAR_MIPMAP_LINEAR // tex.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); // tex.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); // tex.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); // tex.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, // GL2.GL_LINEAR_MIPMAP_LINEAR); } else { texture.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); texture.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); } }
public final void addFrame(final GL gl, final Class<?> context, final String imageResourcePath, final String imageSuffix) throws IOException { final URLConnection urlConn = IOUtil.getResource(imageResourcePath, context.getClassLoader(), context); if(null != urlConn) { final TextureData texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, imageSuffix); final Texture tex = new Texture(getTextureTarget()); tex.updateImage(gl, texData); addFrame(gl, tex); } } public final int getFrameCount() { return frames.size(); }