List of usage examples for org.lwjgl.opengl GL11 glBindTexture
public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture)
From source file:zildo.fwk.gfx.filter.CloudFilter.java
License:Open Source License
@Override public boolean renderFilter() { super.startInitialization(); updateTile(0, 0, u, v, Reverse.NOTHING); this.endInitialization(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity();/* www .j a v a2 s . co m*/ GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glTranslatef(0, -sizeY, 1); GL11.glColor3f(1.0f, 1.0f, 1.0f); float colorFactor = 0.2f; GL11.glColor4f(colorFactor, colorFactor, colorFactor, 0.1f); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_ZERO, GL11.GL_ONE_MINUS_SRC_COLOR); GL11.glBindTexture(GL11.GL_TEXTURE_2D, ClientEngineZildo.tileEngine.texCloudId); super.render(); GL11.glDisable(GL11.GL_BLEND); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); return true; }
From source file:zildo.fwk.opengl.Utils.java
License:Open Source License
public static int generateTexture(int sizeX, int sizeY) { IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL int textureID = buf.get(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, adjustTexSize(sizeX), adjustTexSize(sizeY), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); return textureID; }
From source file:zildo.fwk.opengl.Utils.java
License:Open Source License
public static void copyScreenToTexture(int p_texId, int p_sizeX, int p_sizeY) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, p_texId); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 0, 0, p_sizeX, p_sizeY, 0); }
From source file:zildo.platform.engine.LwjglSpriteEngine.java
License:Open Source License
@Override public void render(int floor, boolean backGround) { // Display every sprites GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_BLEND);/*from w w w. jav a 2s . co m*/ float[] color = textureEngine.graphicStuff.getFloat(GL11.GL_CURRENT_COLOR, 4); Vector3f ambient = ClientEngineZildo.ortho.getAmbientColor(); Vector4f ambient4f = new Vector4f(1, 1, 1, 1); if (ambient != null) { color[0] = ambient.x; color[1] = ambient.y; color[2] = ambient.z; ambient4f = new Vector4f(color[0], color[1], color[2], 1); } // Respect order from bankOrder boolean endSequence = false; int posBankOrder = 0; // Retrieve the sprite's order int[][][] bankOrder = ClientEngineZildo.spriteDisplay.getBankOrder(); int phase = (backGround) ? 0 : 1; while (!endSequence) { int numBank = bankOrder[floor][phase][posBankOrder * 4]; if (numBank == -1) { endSequence = true; } else { // Render the n sprites from this bank int nbQuads = bankOrder[floor][phase][posBankOrder * 4 + 1]; int iCurrentFX = bankOrder[floor][phase][posBankOrder * 4 + 2]; int alpha = bankOrder[floor][phase][posBankOrder * 4 + 3]; EngineFX currentFX = EngineFX.values()[iCurrentFX]; int texId = textureEngine.getNthTexture(numBank); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // Select the right pixel shader (if needed) if (pixelShaderSupported) { switch (currentFX) { case NO_EFFECT: ARBShaderObjects.glUseProgramObjectARB(0); break; case PERSO_HURT: // A sprite has been hurt ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(1)); ClientEngineZildo.pixelShaders.setParameter(1, "randomColor", new Vector4f( (float) Math.random(), (float) Math.random(), (float) Math.random(), 1)); break; case YELLOW_HALO: ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(2)); ClientEngineZildo.pixelShaders.setParameter(2, "factor", new Vector4f((float) (0.6 + 0.4 * Math.cos(3 * gamma)), 0, 0, 1)); break; case STAR: ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(3)); ClientEngineZildo.pixelShaders.setParameter(3, "noise", new Vector4f(gamma, (float) Math.random(), 0, 1)); break; case FIRE: ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(4)); //ClientEngineZildo.pixelShaders.setParameter(4, "iResolution", new Vector4f(Zildo.viewPortX, Zildo.viewPortY, 0, 0)); ClientEngineZildo.pixelShaders.setParameter(4, "iGlobalTime", new Vector4f(gamma, 0, 0, 0)); break; default: if (currentFX.needPixelShader()) { // This is a color replacement, so get the right ones Vector4f[] tabColors = ClientEngineZildo.pixelShaders .getConstantsForSpecialEffect(currentFX); // And enable the 'color replacement' pixel shader ARBShaderObjects .glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(0)); ClientEngineZildo.pixelShaders.setParameter(0, "Color1", tabColors[2]); //.scale(color[0])); ClientEngineZildo.pixelShaders.setParameter(0, "Color2", tabColors[3]); //.scale(color[0])); ClientEngineZildo.pixelShaders.setParameter(0, "Color3", tabColors[0]); ClientEngineZildo.pixelShaders.setParameter(0, "Color4", tabColors[1]); ClientEngineZildo.pixelShaders.setParameter(0, "curColor", ambient4f); } else { ARBShaderObjects.glUseProgramObjectARB(0); } } } switch (currentFX) { case SHINY: GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); // _MINUS_SRC_ALPHA); GL11.glColor4f(1, (float) Math.random(), 0, (float) Math.random()); break; case QUAD: //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); //GL11.glColor4f(0.5f + 0.5f * (float) Math.random(), 0.5f * (float) Math.random(), 0, 1); GL11.glColor4f(0.7f, 0.6f, 0.8f, 1); break; /* case WHITE_HALO: float r = (float) (0.6 + 0.4 * Math.random()); GL11.glColor4f(r, 0, 0, 1); GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA); break; */ case FOCUSED: GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha / 255.0f); break; case FONT_PEOPLENAME: GL11.glColor4f(0.9f, 0.5f, 0.2f, alpha / 255.0f); break; case INFO: GL11.glColor4f(0.9f, 0.8f, 0.72f, alpha / 255.0f); break; default: color[3] = alpha / 255.0f; textureEngine.graphicStuff.setCurrentColor(color); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); } meshSprites[numBank].render(nbQuads); posBankOrder++; } } // Deactivate pixel shader if (pixelShaderSupported) { ARBShaderObjects.glUseProgramObjectARB(0); } GL11.glDisable(GL11.GL_BLEND); gamma += 0.01f; }
From source file:zildo.platform.engine.LwjglTextureEngine.java
License:Open Source License
@Override public int doGenerateTexture() { scratch.position(0);//from ww w .jav a 2 s.c om // Create A IntBuffer For Image Address In Memory IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0)); // Typical Texture Generation Using Data From The Image int wrapping = GL11.GL_REPEAT; // Wrap texture (useful for cloud) GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrapping); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wrapping); int filtering = GL11.GL_NEAREST; // Linear Filtering GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filtering); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filtering); // Generate The Texture GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, getTextureFormat(), 256, 256, 0, getTextureFormat(), GL11.GL_UNSIGNED_BYTE, scratch); return buf.get(0); }
From source file:zildo.platform.engine.LwjglTextureEngine.java
License:Open Source License
@Override public void getTextureImage(int p_nthTex) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, getNthTexture(p_nthTex)); scratch.position(0);/* w w w. j a v a 2s.c o m*/ alphaChannel = alphaTab[p_nthTex]; GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, getTextureFormat(), GL11.GL_UNSIGNED_BYTE, scratch); }
From source file:zildo.platform.engine.LwjglTextureEngine.java
License:Open Source License
@Override public int loadTexture(String name) { try {//from w w w. j av a 2 s. c o m Texture tex = TextureLoader.getTexture("PNG", new FileInputStream(Constantes.DATA_PATH + "textures/" + name + ".png")); int id = tex.getTextureID(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Typical Texture Generation Using Data From The Image int wrapping = GL11.GL_REPEAT; // Wrap texture (useful for cloud) GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrapping); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wrapping); int filtering = GL11.GL_NEAREST; // Linear Filtering GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filtering); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filtering); // Store texture id textureTab[n_Texture] = tex.getTextureID(); alphaTab[n_Texture] = true; // Ready for next one n_Texture++; return tex.getTextureID(); } catch (Exception e) { throw new RuntimeException("Can't load texture " + name, e.getCause()); } }
From source file:zildo.platform.filter.LwjglBilinearFilter.java
License:Open Source License
@Override public boolean renderFilter() { graphicStuff.fbo.endRendering();/*ww w. j a v a 2s . c o m*/ // Select right texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); // Disable blend GL11.glDisable(GL11.GL_BLEND); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glTranslatef(0, -sizeY, 1); // This filter is in charge to alter all screen colors Vector3f v = ClientEngineZildo.ortho.getFilteredColor(); GL11.glColor3f(v.x, v.y, v.z); // Draw texture with depth super.render(); // Reset full color GL11.glColor3f(1, 1, 1); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); return true; }
From source file:zildo.platform.filter.LwjglBlendFilter.java
License:Open Source License
@Override public boolean renderFilter() { int currentSquareSize = getCurrentSquareSize(); graphicStuff.fbo.endRendering();//from w ww . j a v a 2 s . c o m // Get on top of screen and disable blending GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glTranslatef(0, -sizeY, 0); Vector3f v = ClientEngineZildo.ortho.getFilteredColor(); GL11.glColor3f(v.x, v.y, v.z); // Draw squares int nSquareX = Zildo.viewPortX / currentSquareSize; int nSquareY = Zildo.viewPortY / currentSquareSize; GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); if (currentSquareSize == 1) { // Square size=1 means this effect is useless ! super.render(); } else { GL11.glBegin(GL11.GL_QUADS); for (int i = 0; i < nSquareY + 1; i++) { for (int j = 0; j < nSquareX + 1; j++) { ClientEngineZildo.ortho.boxTexturedOpti(j * currentSquareSize, i * currentSquareSize, currentSquareSize, currentSquareSize, (j * currentSquareSize) / (float) ScreenFilter.realX, (i * currentSquareSize) / (float) ScreenFilter.realY, 0, 0); } } GL11.glEnd(); } GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glDisable(GL11.GL_BLEND); return true; }
From source file:zildo.platform.filter.LwjglBlurFilter.java
License:Open Source License
@Override public boolean renderFilter() { boolean result = true; graphicStuff.fbo.endRendering();//from ww w. ja va 2 s .c o m // Get on top of screen and disable blending GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glTranslatef(0, -sizeY, 0); //GL11.glDisable(GL11.GL_BLEND); if (nImagesSaved < nImages) { // All images are not stored yet. So we just display the current one. nImagesSaved++; GL11.glBindTexture(GL11.GL_TEXTURE_2D, texBuffer[currentImage]); super.render(); result = false; } else { super.focusOnZildo(); // Draw each image, with intensified colors for (int i = 0; i < nImages; i++) { float coeff = startCoeff + i * (incCoeff / nImages); GL11.glColor4f(coeff, coeff, coeff, 1.0f); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texBuffer[(i + currentImage + 1) % nImages]); super.render(); if (i == 0) { // Enable blend from second one GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); //_MINUS_SRC_ALPHA); } } } GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glDisable(GL11.GL_BLEND); // Switch currentImage = (currentImage + 1) % nImages; return result; }