Can't use multiple color in stream buffer

Idk what am i missing but i tried to generate a texture that has more that one color but it always shows only one.

self.radius = 200

self.buffer = buffer.create(self.radius * self.radius, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
self.stream = buffer.get_stream(self.buffer, hash("rgb"))

for y = 1, self.radius do
	for x = 1, self.radius do
		local index = (y-1) * self.radius * 3 + (x-1) * 3 + 1

		if y < self.radius / 2 then
			-- orange
			self.stream[index + 0] = 0xff
			self.stream[index + 1] = 0x80
			self.stream[index + 2] = 0x10
		else
			-- blue
			self.stream[index + 0] = 0x10
			self.stream[index + 1] = 0x80
			self.stream[index + 2] = 0xff
		end
	end
end

local resource_path = go.get("#sprite", "texture0")
local header = { width=self.radius, height=self.radius, type=resource.TEXTURE_TYPE_2D, format=resource.TEXTURE_FORMAT_RGB, num_mip_maps=1 }
resource.set_texture( resource_path, header, self.buffer )  

the result is just a 200x200 square all in blue, instead of half in blue and another half in orange.

The code looks fine at a glance. Did you figure it out?

1 Like

You are applying the texture to a sprite. Because sprites display only a portion of a texture it might be that the orange portion is out of bounds of the sprite.
Try a quad model with a simple shader instead.

3 Likes

i used a 1x1 sample texture and scale it to the size of buffer didn’t know that it’s not going to work after that i manually resize the image to buffer size it shows the result but it’s not a good solution for me i want to be able to dynamically select my buffer size and project the created buffer on a go

haven’t used quad at all i’ll see what i can do

If you’re drawing to an atlas, keep in mind that it will resize itself to the (larger) nearest power of two in both width and height. When you assign this to a sprite, the texture you drew to the atlas is not placed at (0, 0) on the atlas, but at (0, height). This would cause problems if your sprite and your atlas are not the exact same size, since your texture is offset by (height - texture size).

3 Likes