[android-developers] OpenGL Textures and Transparency. Square holding the texture still shows.
Hello, I've run into a problem using OpenGL with Android. I'm trying to create a transparent sprite that appears in my game application. The sprite is (.png) format and contains transparent values (alpha=0) around the image. Loading the image isn't a problem. I'm able to have the image load onto a VBO square. The problem is that this VBO square shows, it's color being the same that is set with: glClearColor(0, 0, 0, 1); In the game scene I have a bunch of VBO cubes that surround the area constantly moving towards the viewer. Randomly, the sprite I was talking about will take the place of one of these cubes. Then, when more cubes spawn from the far back. I can see the square that the sprite is drawn on. I honestly think this has to do with depth testing some how... because when the sprite is in front of the cube. It would make sense for the depth testing to hide parts of the cube (the parts covered by the square). The problem is that when I disable depth testing, the sprites will not appear in front of the cube. How can I make it so the sprites will appear in front, yet not cover of the behind cubes? Thanks, Nick. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] OpenGL textures not working.
I am having some trouble getting textures to work in OpenGL. I explained my problem in detail here: http://stackoverflow.com/questions/8704258/how-to-render-textured-primitives-in-android-opengl-es-2-0 . For the sake of neatness I won't write it again here. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] OpenGL textures fail to load, white image
Greetings, I've been having an interesting problem with a game I'm developing. The game is being built using the cocos2d-android-1 library. All sprites are loaded from ARGB files. They are of varying size (not powers of 2). When I deploy a test build to my Nexus One after making any code changes (anything that forces the device to redeploy the APK) all the sprites show up just fine. Alpha shows up correctly, etc. If I rerun the application from my N1, it will be missing some or all of the textures at random. Occasionally this is my splash screen sprite. Sometimes it is sprites of individual items on the screen. There doesn't seem to be any rhyme or reason as to what sprites are rendered and which are not. All the items move and behave correctly, but the sprites have been rendered with white textures. If I reboot my phone, the game loads fine for the initial play through, but subsequent play throughs have the bug again. Now I've done some research and it looks like some people had issues using non-power of 2 images for openGL textures. However this doesn't explain why my non-power of 2 textures render fine on the first passthrough, and fail on subsequent passthroughs. Also I've noticed that this problem seems to occur more often when I have the application loading images from the sdcard. If I load the images from the assets folder and use the AssetManager I don't run into the issue as much, although I did see it very rarely. Is there some type of file locking going on here that is preventing subsequent playthroughs from accessing the image file? When a bitmap is loaded, does it prevent other applications from reading the image file while it's in use? I'm going to try using sprite sheets and/or switching everything to use powers of 2, but I'm not sure if that will fix it. I swear it is something wrong with how the files are loaded (asset folder vs folder on sdcard) that is prevent subsequent playthroughs from correctly loading the texture. This is the code I'm using to read in the files: private static HashMap textureMappings = new HashMap(); public static final CCTexture2D addTexture(String filePath) { if(filePath.contains("../")) { return null; } CCTexture2D rtn = textureMappings.get(filePath); if (rtn == null) { String path = Constants.DEFAULT_PATH + filePath; File f = new File(path); if (f.exists()) { Bitmap bmp = BitmapFactory.decodeFile(Constants.DEFAULT_PATH + filePath); rtn = new CCTexture2D(bmp); textureMappings.put(filePath, rtn); } } return rtn; } This is the constructor for CCTexture2D: public CCTexture2D(Bitmap image) { CGSize imageSize = CGSize.make(image.getWidth(), image.getHeight()); CGAffineTransform transform = CGAffineTransform.identity(); int width = toPow2((int) imageSize.width); int height = toPow2((int) imageSize.height); while (width > kMaxTextureSize || height > kMaxTextureSize) { width /= 2; height /= 2; transform = transform.getTransformScale(0.5f, 0.5f); imageSize.width *= 0.5f; imageSize.height *= 0.5f; } if (imageSize.width != width || imageSize.height != height) { Bitmap bitmap = Bitmap.createBitmap(width, height, image.hasAlpha() ? Bitmap.Config.ARGB_ : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(image, 0, 0, null); image.recycle(); image = bitmap; } init(image, imageSize); } This is what happens in init: private void init(Bitmap image, CGSize imageSize) { mBitmap = image; mWidth = image.getWidth(); mHeight = image.getHeight(); mContentSize = imageSize; // _format = image.getConfig(); _maxS = mContentSize.width / (float) mWidth; _maxT = mContentSize.height / (float) mHeight; _texParams = _gTexParams; ByteBuffer vfb = ByteBuffer.allocateDirect(4 * 3 * 4); vfb.order(ByteOrder.nativeOrder()); mVertices = vfb.asFloatBuffer(); ByteBuffer tfb = ByteBuffer.allocateDirect(4 * 2 * 4); tfb.order(ByteOrder.nativeOrder()); mCoordinates = tfb.asFloatBuffer(); if(mBitmap.getConfig() == Bitmap.Config.ARGB_) premultipliedAlpha = true; } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For
Re: [android-developers] opengl textures
On 7 February 2011 18:57, bob wrote: > Do opengl textures on Android have to be a width and height that is a > power of 2? In general: yes as some devices will won't handle your textures otherwise. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] opengl textures
On 7 February 2011 19:22, Marcin Orlowski wrote: > On 7 February 2011 18:57, bob wrote: >> Do opengl textures on Android have to be a width and height that is a >> power of 2? > > In general: yes as some devices will won't handle your textures otherwise. It applies to width (for quite obvious reasons), yet I am not sure about height and can't check now. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] opengl textures
Do opengl textures on Android have to be a width and height that is a power of 2? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] OpenGL Textures
Hello All, I'm learning OpenGL on my own atm and I have a question about texturing a surface: I can create a simple polygon like this: public class Square { // Our vertices. private FloatBuffer colorBuffer; float[] colors = { .5f, .5f, 0f, .2f, // vertex 0 red 0f, 1f, 0f, .2f, // vertex 1 green 0f, 0f, 1f, .2f, // vertex 2 blue 1f, 0f, 1f, .2f, // vertex 3 magenta }; private float vertices[] = { -.7f, .04f, -.5f, // 0, Top Left -.7f, -.04f, -0.5f, // 1, Bottom Left .7f, -.04f, 0.05f, // 2, Bottom Right .7f, .04f, 0.05f, // 3, Top Right }; private short[] indices = { 0, 1, 2, 0, 2, 3 }; Then I load all of that info into the approriate buffers and draw it to the screen with a call to: gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer); My question: I'm looking for a good example of how to take an image and texture it to the surface. (I'm looking for a good book on JOGL with examples.) Any suggestions are appreciated. Thanks, Josh Beck Northeast ISD -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] OpenGL Textures must specify GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER
This tricked me up for a few hours and I couldn't see anywhere that is was discussed. When running on the Emulator, you don't have to specify the GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER. However, when running on the HTC G1, you do! So make sure you have something like this in you code: gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); Cheers. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---