Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Modify Texture - Gideros Forum

Modify Texture

Hello

First: I'm new to this forum, and my english is not very good. Sorry about.

My problem is. I want to write a small retro game and stuck with texture modify.

I want a texture from the size 256x256 and modify parts of it every frame.


My first thought:

local tex = Texture.new( "images/test.png", false )
local bm = Bitmap.new( tex )

One time "Texture.new", and then each frame delete bitmap and recreate it.
The texture is stored in CPU memory and the bitmap in GPU memory, right?

But how can I have access to the pixel data from the texture?


My other thought:

local size = 256
local stringbm = string.rep( string.char( 255,255,0,255 ), size*size )
local tex = Texture.new( stringbm, size, size, false, {} )
local bm = Bitmap.new( tex )

This try stores the texture data in a string. And I want to delete the bitmap and texture every frame, modify the stringbitmap, and then recreate it.
But I cannot modify the string in Lua...


Have anyone a good problem solving for me?

Likes: antix

+1 -1 (+1 / -0 ) Share on Facebook

Comments

  • rrraptorrrraptor Member
    Accepted Answer
    Use RenderTarget
    local random=math.random
    local w,h = 256,256
    local rt = RenderTarget.new(w,h)
    local btm = Bitmap.new(rt)
    stage:addChild(btm)
     
    for y = 1, h do 
    	for x = 1, w do 
    		rt:clear(random(0xffffff),1,x,y,1,1) -- can be read as setPixel with random color at x,y
    	end
    end

    Likes: keszegh

    +1 -1 (+1 / -0 ) Share on Facebook
  • keszeghkeszegh Member
    btw i think that the texture is stored in gpu memory if it fits. and the bitmap is not storing it again, just a pointer to it, or something like this. so my guess would be that 100 bitmaps with same texture do not need much more memory than 1 bitmap with one texture. am i right, experts?
  • wefewefe Member
    RenderTarget is a very good solution!
    I didn't think in that direction at all.

    When texture and bitmap are stored in GPU memory. Then it is clear why it is not so easy to read.

    Thank you very much!
  • hgy29hgy29 Maintainer
    keszegh said:

    btw i think that the texture is stored in gpu memory if it fits. and the bitmap is not storing it again, just a pointer to it, or something like this. so my guess would be that 100 bitmaps with same texture do not need much more memory than 1 bitmap with one texture. am i right, experts?

    Totally right, the bitmap holds the mesh only, the texture is stored independently and referenced by any other sprite that use it

    Likes: keszegh

    +1 -1 (+1 / -0 ) Share on Facebook
Sign In or Register to comment.