SpuTTer
|
 |
«
Posted
2003-11-17 00:00:56 » |
|
I've created a PNG with a transparent background and an alpha channel. I was able to get it to be transparent with blending, but the "main" part of the image blends in with the background as well. How do I get the "sprite" to be solid. I switched from blending to Alpha, but my image isnt loading correctly. It's all "fuzzy" now. Im using the PNG format with an Alpha map. Im trying simulate 2D in Ortho mode. Im using the texture loader from the Nehe demos. It seems to have issues when I changed my glTexImage2D values to GL_RBGA.... I have checked my image out, it is a 32 bit image with alpha channel. Here are my settings: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| GL.glEnable(GL.GL_TEXTURE_2D); GL.glShadeModel(GL.GL_SMOOTH); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.glClearDepth(1.0); GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); GL.glAlphaFunc(GL.GL_GREATER,0.0f); GL.glEnable(GL.GL_ALPHA_TEST); GL.glEnable(GL.GL_CULL_FACE); GL.glViewport(0,0,Window.getWidth(),Window.getHeight()); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); GL.glOrtho(0.0f,Window.getWidth(),Window.getHeight() ,0.0f,-100f,100f); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); |
Here is my quad draw code 1 2 3 4 5 6 7 8 9 10
| GL.glBindTexture(GL.GL_TEXTURE_2D, texture[tile]); GL.glBegin(GL.GL_QUADS); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(x*32f, (y + 1)*32f, z); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f((x + 1)*32f, (y + 1)*32f,z); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f((x + 1)*32f, y*32f, z); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(x*32f, y*32f, z); GL.glEnd(); |
Loader: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| private final static int loadTexture(String path,int trans) {
Image image = (new javax.swing.ImageIcon(path)).getImage(); BufferedImage tex = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = (Graphics2D) tex.getGraphics(); g.drawImage(image, null, null); g.dispose(); AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -image.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); tex = op.filter(tex, null); ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight()); byte data[] = (byte[]) tex.getRaster().getDataElements( 0, 0, tex.getWidth(), tex.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL.glGenTextures(buf); GL.glBindTexture(GL.GL_TEXTURE_2D, buf.get(0)); GL.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); GL.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); int type=GL.GL_RGB; if (trans==1) { type=GL.GL_RGBA; }
GL.glTexImage2D( GL.GL_TEXTURE_2D, 0, type, tex.getWidth(), tex.getHeight(), 0, type, GL.GL_UNSIGNED_BYTE, scratch);
return buf.get(0); } |
thanks!
|