You are not logged in.

#1 2009-04-07 17:40:09

spiffen
Member

Draw an image or tile to a texture instead of screen.

Would be nice to be able to draw a texture to another texture instead of the screen. Also it would be nice if it had alpha blending support = working the same as when drawing to the screen buffer.

I've done this by using Get- and SetPixel (kind of ugly imo), but I guess it can be done in a much nicer and faster way.

Last edited by spiffen (2009-04-07 22:24:36)

Offline

 

#2 2009-06-27 17:49:19

suloku
Member

Re: Draw an image or tile to a texture instead of screen.

So, how did you exactly make that?

Get the pixels from the screen buffer and then setting them onto a new texture with the correct width/height?

Offline

 

#3 2009-06-27 18:48:38

Crayon
Bad Mother Fucker

Re: Draw an image or tile to a texture instead of screen.

suloku wrote:

So, how did you exactly make that?

Try using GRRLIB_CreateEmptyTexture:

Code:

/**
 * Create an empty texture.
 * @param w Width of the new texture to create.
 * @param h Height of the new texture to create.
 * @return A GRRLIB_texImg structure newly created.
 */
GRRLIB_texImg *GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h)

Check lesson2 for a demo: http://code.google.com/p/grrlib/source/ … rce/main.c

Offline

 

#4 2009-07-22 11:09:21

BlueChip
Moderator

Re: Draw an image or tile to a texture instead of screen.

I need this feature myself for my current project, so I've researched and written it.
I have not fully tested it yet, so I have not posted it yet.
If anyone wants this urgently in "beta", just ask.
The algorithm I have implemented is:  "normal" a-over-b alpha-compositing [see wikipedia]
This is the same algorithm used by PSP, PhotoShop, GIMP & Flash as their "normal" algorithm
I have also designed an algorithm not found in any art packages which will allow you to compose as if the light source is behind the canvas (not behind the viewer) ...this will perform fully "commutative alpha-compositing"
I expect to have it tested (and uploaded) by the weekend ...watch the 'contributions' forum
Getpixel and putpixel could (deabteably) be implemented as macros rather than inline functions - but they are neither ugly nor slow algorithms ...and once inline'd (however you achieve that) I really can't see a better or faster way to write them

On that note, if anyone can explain the "fucken algorithm found my nonameno" I would love to know how and why tex's are stored in such a crazy format smile


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

#5 2009-07-22 20:27:43

spiffen
Member

Re: Draw an image or tile to a texture instead of screen.

Wow. That is really cool.. I made a try but never got the alpha blending part to work 100%..

Offline

 

#6 2009-07-22 20:44:16

Crayon
Bad Mother Fucker

Re: Draw an image or tile to a texture instead of screen.

I wanted a feature like that for the buttons in my software.

My CPU is tired of rendering the image AND the text each time. He told me, "dude, do that once and put the result in texture". Of course the text is using the alpha channel to make characters a lot nicer on the screen.

I gave it a tried, but I failed.

I volunteer to beta test your code, whenever it's ready wink

Offline

 

#7 2009-08-18 01:01:09

BlueChip
Moderator

Re: Draw an image or tile to a texture instead of screen.

This is now included in v4.1.0 ...However, I am not happy at how it works ...it uses getpixel and setpixel and is terribly slow ...I'm sure its not the math ...I suspect that textures are held in video ram which is clasically slow to access...with 8 readsand 4 writes per pixel, that would explain the slowness ...there must be a better way, but for now, this DOES work ...see composition demo

BC


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

Board footer

Powered by FluxBB