Jump to content

Load Texture pieces


ParaToxic
 Share

Recommended Posts

Hi ParaToxic,

 

forget Blitz3D (LoadAnimTexture or so..) it just a tricky function/structure to hide the texture coordinate calculations.

You can load the texture above in a whole and then display a "frame" by setting the uv coordinates to

x1 = row / maximumRow;

y1 = col / maximumCol;

x2 = x1 + (1.0f / maximumRow);

y2 = y1 + (1.0f / maximumCol);

 

This is just one method, i bet there are plenty different. You just have to see the whole texture from 0,0 to 512,512 as 0,0 to 1,1 and then "scale" it to your needs.

 

E.g.:

If you have a 512x512 texture and want to show 0,0 to 256,256 then you have to write

x1 = 0

y1 = 0

x2 = 0.5

y2 = 0.5

 

ps. x1/y1 and x2/y2 are the uv coordinates if you see the texture as a simple rectangle (they are the corners).

 

Hope this helps you.

  • Upvote 1
Link to comment
Share on other sites

So now I made a class with some function for that.

Imagine I have a texture and at the top left is an image like in the pic I posted.

I load the texture to my TTexture variable and create a new TTexture with the height and width of 128.So I set my 128*128 texture with SetBuffer(display_texture); and draw only a piece of the first texture like this :

 

SetBuffer(display_texture);
DrawImage(loaded_texture,0,0,128,-128); // x and y are 0 ,so we see the left top image

 

But I can't see anything when I display the created image.

Does anyone know how to make that?

Link to comment
Share on other sites

You can draw a little piece of big texture to little texture. Then you can use that little texture as you want.

 

 

Code from the video:

--preparations
local cbst = LoadTexture("abstract::cobblestones.dds")
local buf = CreateBuffer(128, 128, BUFFER_COLOR)
local tex = CreateTexture(128, 128, TEXTURE_RGB)
SetColorBuffer(buf, tex, 0, 0)

--render image to custom buffer
SetBuffer(buf)
DrawImage(cbst, MouseX() - 512, -(MouseY() - 512), 1024, -1024)
SetBuffer(BackBuffer())

--draw custom buffer to back buffer
DrawImage(tex, 100, 100, 128, 128)

  • Upvote 2
Link to comment
Share on other sites

I heard that it's faster to load the frames as separate textures and only change the MaterialTexture.Is that right ,or would you say that the methode with the 2nd buffer is better?

 

I think they are the same. They different only in getting small texture (grabbing it from the big one vs loading from separate file). Since it happens only once at starting game the difference has no matter.

 

If you are looking for the fastest way, I think it would be fastest to use one big texture and special shader to change UV coordinates.

Link to comment
Share on other sites

Rendering something to buffers every frame is not the best idea. Do it only if your picture changes every frame (for post-effects, mirrors, picture in picture etc.).

 

In other cases render picture only once to get desired texture. And then use this texture multiple times where you need to draw it.

I think you can use such approach for GUI.

Link to comment
Share on other sites

Thats not exact the way i thought you would go.

 

You guys know the video where Josh creates a cube on 3 different ways ?

One way was to create it by code with AddVertex etc.

 

That was my Idea, you have 1 big texture and then update the UV coordinates of your mesh/plane :)

  • Upvote 1
Link to comment
Share on other sites

I think I will make a shader but later ,because I have to finish my own class :)

 

Does somebody know how to make a frameupdater (for animationframes) for integers which is dependent from the appspeed?

I tryied it with frame = frame + 0.1 * speed * AppSpeed() but when frame is an integer it doesn't work.

Link to comment
Share on other sites

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...