Its some years ago when i started to code an own texture generator which was very slow and had only a few very simple generators (can be found somewhere on the forum here). Sadly i lost all the sources in the past due fact of a bad hd crash. Now i am very motivated to code a new one, esp. for my actually project i am working on and where i could need some nice simple and fast texture generator functions to create simple textures.
I want to code, ask you and help other guys here how and where to start a good, flexible and fast texture generator with some basic functions (generators, operations, filters). So i will talk and ask here about some basic things, which may not be the best solution and we can hopefully discuss here to show better solutions.
You all may know Windows GDI and possible GDI+ ... Personally i think its not good to use GDI nor GDI+ for drawing 2D objects like "Line, Box, Oval, Circle, Plot", because GDI is to slow and dont support Antialiazed drawing like GDI+ where we need to install GDI+ for. Generating textures at runtime needs a lot of calculations/times and so we want to have a good, easy and fast solution instead long calculating times!
The idea is to have a hand full of own "Generators" where we are drawing needed things by using our own code/algos. Possible Generators we should have for a useable TextureGenerator can look like this:
TexGen_Flat( RGBA.l ) or TexGen_Flat( Width.l, Height.l, RGBA.l )
TexGen_Rect( xPos.l, yPos.l, Width.l, Height.l, RGBA.l )
TexGen_Glow( xPos.l, yPos.l, Width.l, Height.l, Gamma.l, RGBA.l )
TexGen_Noise( Octaves.l, Scales.l, Seed.l, RGBA.l )
Ofcourse we could add many other generators as we want and needing. Generators are just only one part of a texture generator. Another things we need are so called Deformation Effects and Color Operations.
TexFx_RotoZoom( ...)
TexFx_SineDistort( ... ) or TexFX_Distort( ...) by using Red and Blue Colors as input i.e.!?
TexFx_Twirl( ... )
TexCol_Blur()
TexCol_Invert()
TexCol_Color()
TexCol_Normal()
As you can see, you could add a lot of funtions to your generator... but dont use to much of them if you want have a small tiny generator. Possible you know the so called "SinePlasma Textures". I think you dont need to add this function to your generator, because you could create the same thing using TexGen_Glow() and TexFX_RotoZoom()... So thinking about some basic operations can save you some engine code by doing things on another way. A checkerboard texture can be created by an own Checkerboard Generator or just by using TexGen_Rect() and TexFX_RotoZoom().
Here are some small and simple generator sources:
; thanks to for the idea to create this with XOr *sweet*, which is smaller
; as my old bloody version
Procedure TexGen_Checkerboard( x_size.l, y_size.l, Color1.l, Color2.l)
Protected Color.l, x1.l, y1.l, x2.f, y2.f
For y = 0 To TextureHeight -1
For x = 0 To TextureWidth -1
If ((x / x_size) & 1) ! ((y / y_size) & 1) = 0
Color = Color1
Else
Color = Color2
EndIf
Plot( x,y, RGB(color, color, color))
Next
Next
EndProcedure
; this is a silly function without AA and i thought about it... can be done with two TexGen_Glow() ^^
; original source from angelcode website
Procedure TexGen_CircleEx( cx.l, cy.l, r.l, thickness.l, red.f, green.f, blue.f)
w.l = TextureWidth
h.l = TextureHeight
Define.l x, y, count
count = r + thickness
If( cx - count < 0 ) : cx = cx + w : EndIf
If( cy - count < 0 ) : cy = cy + h : EndIf
x = 0;
While( x <= count )
y = 0;
While( y <= count )
pr.l = Int(Sqr(x*x + y*y));
If( (pr < r + thickness/2) And (pr >= r - thickness/2) )
Define.l px, py
px = (cx+x)%w;
py = (cy+y)%h;
Plot ( px, py, RGB(red,green,Blue))
px = (cx-x)%w;
py = (cy+y)%h;
Plot ( px, py, RGB(red,green,Blue))
px = (cx-x)%w;
py = (cy-y)%h;
Plot ( px, py, RGB(red,green,Blue))
px = (cx+x)%w;
py = (cy-y)%h;
Plot ( px, py, RGB(red,green,Blue))
EndIf
y=y+1
Wend
x=x+1
Wend
EndProcedure
i will check my old backup DVDs and will post some other procedures if i find some of them...
As we know now, we will use our own drawing algos/procedures which are faster by drawing directly in the memory (on the texture) without using GDI/GDI+.... This makes the TexGen functions (Generators, filters....) OS independent and portable to other systems too!
I am not really sure what is the best way to start with. Using an Array like TexSize * TexSize * 4 bytes for RGBA values is silly and still slow i think... So i think allocating a memoryblock TexWidth * Texheight * 4 bytes for RGBA seems to be a better and faster solution. I am not really sure if we just only need to alloc this memory block size (without BMP header for example)... or using WinAPI structures too...
Structure BITMAPINFOHEADER
biSize.l
biWidth.l
biHeight.l
biPlanes.w
biBitCount.w
biCompression.l
biSizeImage.l
biXPelsPerMeter.l
biYPelsPerMeter.l
biClrUsed.l
biClrImportant.l
EndStructure
Structure BITMAPFILEHEADER
bfType.w
bfSize.l
bfReserved1.w
bfReserved2.w
bfOffBits.l
EndStructure
So it would be nice to know from the real texture generations gurus here (hello mind, rbraz

what the best way and how/where to start if you want to load the generated texture with DX9 from memory ^^ thanks