Render to Texture at runtime?

BlitzMax Forums/OpenGL Module/Render to Texture at runtime?

Dud(Posted 2005) [#1]
Hi all,

I have written a program in BlitzMax/OpenGL to create a random terrain which so far is working great. I can texture my terrain using a pre-drawn texture, but as I am generating my terrain at runtime I would prefer to also generate a suitable terrain texture at runtime too. I plan to create the various colours of pixels in the texture based on the various heights within the terrain - so ideally I am looking for some kind of "Render to Texture" function in OpenGL.

After doing a bit of searching I've discovered that such a feature doesn't seem to exist in older versions of OpenGL but is supported in newer versions through extensions?

I was wondering if anybody could suggest a way I could use the standard functions within the version of OpenGL supported by BlitzMax to create a texture at runtime. I'm still new to OpenGL and am not familiar with its many functions so there might be an easy solution (I hope so!). Speed is not important to me as my terrain, once generated, will remain static - so I only need to create the texture once at the start of my program.

Any suggestions would be much appreciated.

Dud


ImaginaryHuman(Posted 2005) [#2]
I am thinking you would need one big texture to cover the entire landscape, containing an image where the height of each piece of land is a different color ... not sure if there are other methods such as something along the lines of voxels?


Dud(Posted 2005) [#3]
Yes that's exactly what I want and plan to do. I can already stretch a texture over my landscape. What I dont know is how to create a texture on-the-fly i.e. how to actually get my color values from a 2d array in memory into an actual texture object that opengl can use.


Chris C(Posted 2005) [#4]
Global skyi=LoadPixmap("sky2.png")
Global sky=bglTexFromPixmap( skyi )
.
.
.
	For Local x:Int=1 To 200
WritePixel(skyi,Rand(0,255),Rand(0,255),rnd(0,255)+(Int(rnd(0,255)) Shl 8)+(Int(rnd(0,255)) Shl 16))
	next
.
.
.
sky=bglTexFromPixmap( skyi )


but only do bgltextfrompixmap for as few text's as
needed because transfering multiple textures to vid
ram will be slow...


Chris C(Posted 2005) [#5]
Messed around with this...

bgltextfrompixmap can be a bit slow with mipmap, so you might
want to turn mipmaps off for that texture

If we're real lucky Mark will give us rendering to
different contexts like a texture...

but that can be a little problematic with multiple platforms


Dud(Posted 2005) [#6]
Chris,

Many thanks for this simple explanation - I'm new to BlitzMax too so hadn't even considered using bgltextfrompixmap - seems obvious now! Speed shouldn't be an issue for me as I only want to transfer one texture using this method.

Regards
Dud


bradford6(Posted 2005) [#7]
http://www.blitzbasic.com/Community/posts.php?topic=43478