Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Deferred loading of textures

edited September 2012 in Bugs Posts: 666

I'm curious if what i am trying to do is illega with OpenGL, or why this problem happens...
i am defining a set of rects to render in a 3D environment. When I use addRect (amd i suspect anything with textures) I can get my texture to properly apply if it is loaded. But, if i load my texture after the fact, it doesn't seem to apply.

Code snippet:

    for x=1,7 do
        idx=road:addRect(0,roadsz.y*x,roadsz.x, roadsz.y)
        road:setRectTex(idx ,0,0,1 ,1)
    -- load your texture before drawing
    -- so, how would we do a deferrred load?
--notice that x goes from 1 to 7 becuase we are hacking..idx also went from 1 to 7
    road.texture= readImage("Documents:road")
    for x=1, 7 do

I would expect to see the textures load after the second loop. Nope.

I also added a seperate rect and added the texture afterwards, and that single rect gets the texture.

So, how would Ii reset the texture coords / map on an existing set of rects?



  • I'm amazed - no one has any ideas on this?

  • SimeonSimeon Admin Mod
    Posts: 5,714

    .@aciolino I believe this is due to the way mesh() allocates its internal buffers. If you don't assign a texture then it won't add a texture coordinate buffer. This behaviour will be changed, as I think the mesh should allocate a buffer regardless.

  • Thank you! So, if I assign a dummy texture, can I replace the dummy later? I haven't tried that yet.

  • SimeonSimeon Admin Mod
    Posts: 5,714

    Yes, that should work.

  • I can validate that is DOES!

  • Another hint: One thing I have experienced is that the texture must have the same size. I wanted to exchange textures at runtime. it works, but only if the size is the same.

  • edited September 2012 Posts: 666

    Uh oh. Rally? I thought I tested this with different size textures...maybe they were similarly sized if codea is aligning them in the background...

  • I think you wont see it for every texture. e.g. when you switch from a 256 texture to a 512, then only the first quarter is used (256x256) from the new texture. you maybe wont recognize this on a texture like sand, dirt, marble.

  • SimeonSimeon Admin Mod
    Posts: 5,714

    It should just switch, regardless of size. The only thing setting a texture does is force mesh to allocate a texture coordinate buffer.

Sign In or Register to comment.