![]() |
|
Issue with Open GL VBO & Texturing (I guess) - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html) +--- Thread: Issue with Open GL VBO & Texturing (I guess) (/thread-1959.html) |
Issue with Open GL VBO & Texturing (I guess) - Fraggle - Jan 4, 2009 08:01 AM Hi, I am new to Open GL (and still fairly new to Obj-c). I'm trying to use VBO to speed up my Open GL code.. however, I'm stuck since 2 days with my scene not showing any texture. I started by adapting the GL Sprite example, adding some transforms and vbo along the way.. I have tried hard to fix it by myself, but I cant found what is the problem with my code.. so If an expert can spot the bug (and explain what I did wrong), I would gladly appreciate it.. here is the code (i extracted the exact parts, to keep the code simple to read): Code: // Sets up an array of values to use as the sprite vertices.Thanks a lot! Seb Issue with Open GL VBO & Texturing (I guess) - papillon68 - Jan 4, 2009 10:23 AM Hi, are you sure with all those translate and scale your mesh is not off screen ? Have you tried using glDisable(GL_CULL_FACE) ? Sometimes it happened to me that mesh was drawn CCW ... Issue with Open GL VBO & Texturing (I guess) - riruilo - Jan 4, 2009 10:34 AM Try to add glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); after glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); By the way, opengl textures are from up to bottom. Usually when you render or draw your mesh you do: glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_NORMAL_ARRAY); if (m_has_texcoord0) glEnableClientState (GL_TEXTURE_COORD_ARRAY); glEnableClientState (GL_INDEX_ARRAY); draw you mesh glDisableClientState(GL_INDEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); if (m_has_texcoord0) glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); Issue with Open GL VBO & Texturing (I guess) - Fraggle - Jan 4, 2009 11:08 AM Nope, did not work ![]() Still all white, no texture.. Any other idea? Issue with Open GL VBO & Texturing (I guess) - bmantzey - Jan 4, 2009 11:25 PM Step through the code that loads your texture, line by line, ensure that everything is as it should be. I have a hunch it's not finding the texture. If it isn't, just make sure that the texture is included with the project. One difference between Xcode and VisualStudio is, the assets are copied to a bundle where the program accesses the assets. Another thing you can do is, use the absolute path of the texture and see if it works then. (Using the absolute path, is loading it separately from the bundle.) If that's not it, try re-saving your png file. I had a hard time with png's because some of them have weird formatting. I'm not really sure how/why but to get around it, load the png in Photoshop or whatever you use and re-save it with no compression or RLE or any of that stuff. If your model is loading and displaying, applying the texture to it is only a matter of loading the texture and binding it, whether you're using a VBO or passing verts to OpenGL one at a time. Let me know if this helps.
Issue with Open GL VBO & Texturing (I guess) - Fraggle - Jan 5, 2009 12:42 AM Png is loaded fine & it's in the target. (it used to work with a simpler code) My geometry is showing up, animated, but all white. There must be something in the code somewhere.. Issue with Open GL VBO & Texturing (I guess) - riruilo - Jan 5, 2009 01:13 AM You can also try to load a "safe or dummy" texture. Something like this (C++) So you will know if your problem is png loading or not. (4 pixels, 2 white, 2 black, "1" means padding) unsigned char pixels[]={255,255,255,0,0,0,1,1,255,255,255,0,0,0,1,1}; glTexImage2D(GL_TEXTURE_2D,0,3,2,2,0,GL_RGB, GL_UNSIGNED_BYTE, pixels); Issue with Open GL VBO & Texturing (I guess) - Fraggle - Jan 5, 2009 03:46 AM Okay, I found out where was the bug: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT, spriteData); => glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData); Damn me!!! I certainly changed it while trying to fix something else... Thanks for your help everyone. Seb Issue with Open GL VBO & Texturing (I guess) - q2dm1 - Jan 5, 2009 05:20 AM You're creating two separate GL_ARRAY_BUFFER VBOs for the vertex and texture coordinates. There can only be a single bound VBO of a given type (GL_ARRAY_BUFFER ot GL_ELEMENT_ARRAY_BUFFER) at any given time. You can either create a single vertex data structure containing both vertex and texture coordinates or have the texture coordinates follow the vertices in memory and adjust the offset passed to glTexCoordPointer accordingly. Having a combined structure is recommended since there are fewer cache misses when fetching the data. Be careful to pass a correct value for the stride parameter though. Issue with Open GL VBO & Texturing (I guess) - arekkusu - Jan 5, 2009 10:39 AM @q2dm1, while it may be better cache-wise to keep data interleaved in a single buffer object, it's perfectly valid to have multiple ARRAY_BUFFERs. The current buffer is used when you set a pointer or set/get the data. The usage case where you want attributes in separate buffer objects like this is when some of them are static and some are streaming. Issue with Open GL VBO & Texturing (I guess) - q2dm1 - Jan 5, 2009 10:42 AM Learning a new thing every day
|