DrawTexture() - Way more useful than it sounds

Community Forums/Showcase/DrawTexture() - Way more useful than it sounds

Streaksy(Posted 2010) [#1]
I've released something I made ages ago in to the code archives today, under 3D Effects / DrawTexture().

This lets you draw images with transparency, rotation, scaling, filters, all kinds of things, and in real time. Plus the same with textured quads on the screen, text with effects, and texture lines like Line() but with a texture and specified thickness). And AlphaRect, which is like Rect but transparent.

Plus you can be imaginative and use it for a 2D particle engines with the add filter, glows, moody screen overlays with the multiply filter, easy screen fading, fading between images - aswell as the obvious stuff like rotating or transparent sprites.

I think a lot of people will find this useful. It opens a lot of doors. So here's a video of it's demo to show what it's about. If you do use this, please acknowledge me. I'm not saying put me in the credits :P but if you dont want to acknowledge me with the release at least post here that you used it. ;D

All the code is there. =D

HERE IS THE SHORT DEMO: http://www.youtube.com/watch?v=E8PffD_t9m0

Oh, and I should mention I'm releasing this as a precursor to releasing other projects' code that people have asked for, such as my peggle clone, which uses it.

When you use textures for images there is a lot of creative options open to you. Here are some of the things I came up with in a portable library:


DrawTexture(texture,x,y,alpha#,filter,red,green,blue,angle#,width,height,scalex#,scaley#,axisx,axisy) (Alternative to DrawImage)

Filter is the usual. 1=normal, 2=multiply, 3=add
If width and height are ommitted or left at zero, the texture will be drawn in its correct size.
ScaleX# and ScaleY# control the scale, shrinking/stretching it from its center rather than the top-left.
AxisX and AxisY are the point that it rotates around if you use Angle#.

AlphaRect(x,y,width,height,alpha#) (Filled, transparent rectangle)
Uses the current drawing colour.

DrawTextureQuad(texture,x1,y1, x2,y2, x3,y3, x4,y4, alpha#,filter, red,green,blue,u1#,v1#,u2#,v2#) (You specify coordinates of the four corners!)

DrawTextureQuadGrid(texture,x1,y1, x2,y2, x3,y3, x4,y4, alpha#,filter, red,green,blue,u1#,v1#,u2#,v2#, steps) (This draws an interpolated quad so it conforms smoothly to mad shapes.

TexLine(x1,y1 ,x2,y2, thickness, texture, ignorecolour) (Draws a line between the two points with the texture)
This is cool for laser effects, antialiased lines, and all-kinds of things.
If ignorecolour isn't true then the line will be drawn in the current drawing colour.

TextureText(x,y,string$,centerX,centerY, alpha#, filter, shadow, angle#, scalex#, scaley#, axisx, axisy) (Draws text with effects)
This works best when drawing the same strings to the screen over many frames instead of lots of something new every frame. You'd start getting slow-down if you drew a high random number every frame, for example. Don't be scared of it though. It's pretty robust. Oh and drawing with the add-filter (filter=3) is a lot faster for such times when the string keeps changing.

Basically, text strings are made in to textures and it remembers the last 300 of such textures. In the code I call them plates. If filter=3 then the production of the plate is faster because it doesn't require the alpha channel to be primed. Normal is still pretty fast but you wouldn't want a few new plates being generated every game frame. If for some reason I cant think of you want to draw a completely different string to the screen every frame you might get slowdown. If you use it to display stats or messages or dialogue or palyer-names whatever, you'll be fine.



Edit: I remember making an okay bloom with this. I'll try to recreate it. It looked good in certain scenes.

.


RifRaf(Posted 2010) [#2]
Very Nice lib, thanks for sharing.


BlitzSupport(Posted 2010) [#3]
Thanks for all your recent sharing! Some good stuff in there.


puki(Posted 2010) [#4]
I've seen this before.

15 Code Archive entries in less than a month, plus a Sector Editor.

"puki" awaits an explanation.


Streaksy(Posted 2010) [#5]
You accusing me of something? You haven't seen it before because I haven't shared it with a soul until a few days ago.

I've been coding for years and have recently decided to share. There. Explained. I've been adding a lot to the code archives and there is still a lot to come. You're "awaiting an explanation"? Are you joking?


big10p(Posted 2010) [#6]
It's just puki speak. Ignore it.


Streaksy(Posted 2010) [#7]
Noted


DavidDC(Posted 2010) [#8]
Could I texture a triangle with this Streaksy?


jfk EO-11110(Posted 2010) [#9]
Also thanks from me, very useful contribution.


Streaksy(Posted 2010) [#10]
Sorry for the slow response, DavidDC.

You can draw a textured triangle to the screen.. but there's no function here to texture an individual triangle of a mesh. If you need that, email me and I'll make one :P