Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 22, 2017 8:07 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Converting REALbasic Picture to OpenGL texture?
PostPosted: Sun Oct 22, 2006 1:44 am 
Offline

Joined: Sun Oct 16, 2005 3:07 am
Posts: 267
Location: Canberra, Australia
Hi,

I need to be able to convert a REALbasic picture (with mask) into an OpenGL texture. Does anyone know of a plugin or something to do that? The picture is generated on the fly and needs to be converted in real time so saving it to disk and re-opening it isnt an option.

Any help would be greatly appreciated.

thanks!

_________________
Peter
http://www.fracturedSoftware.com
Rondo - Midi made easy.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 22, 2006 2:39 am 
Offline

Joined: Fri Sep 30, 2005 6:55 pm
Posts: 1522
OpenGL just expects a sequence of RGB values in an array, so something similar to this should to the trick:
dim x, y as integer
dim r as RGBSurface
dim mem as memoryBlock
dim c as color

mem = newMemoryBlock(pic.width * pic.height * 3) // 3 is for R, G, and B
r = pic.RGBSurface // make sure pic is 32 bit

for y = 0 to pic.height - 1
for x = 0 to pic.width - 1
c = r.pixel(x, y)
mem.byte(y * pic.height * 3 + x * 3) = c.red
mem.byte(y * pic.height * 3 + x * 3 + 1) = c.green
mem.byte(y * pic.height * 3 + x * 3 + 2) = c.blue
next
next

// the memoryBlock should contain valid texture data now...

There's obvious room for optimization, and it's untested, but that's a general outline on what to do.

_________________
Those who can, do. Those who can't, make excuses.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 22, 2006 3:28 am 
Offline

Joined: Fri Sep 30, 2005 4:48 pm
Posts: 263
Looping through the RGBSurface will work but it's also very slow. Using declares to grab the pixel data from a Picture's handle might be an option, but that can get a little tricky.

The fastest way to get texture data to OpenGL is to skip the RB Picture object entirely, which usually means writing your own image file importer(s). I use a custom plugin to load PNG images into a class that wraps a memoryblock. I could add that functionality to my (public) PNG Utilities plugin if there's enough demand, but it shouldn't be difficult to do something similar in pure RB code for simpler formats such as TGA.

_________________
www.chaoticbox.com ยท REALbasic Stuff
Latest iPhone Game: Silverifsh - pure arcade action.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 23, 2006 2:58 am 
Offline

Joined: Sun Oct 16, 2005 3:07 am
Posts: 267
Location: Canberra, Australia
OK,
Thanks guys, I should have mentioned that I already have a plugin written by my son that does this - but it doesnt work as a universal binary or under windows so I was hoping to find something already done as it would seem to be a common problem.

And yes RGBSurface would be way to slow for what I need. Basically I am generating small clips of text to display and the only way I found I could get a native 'look' rather than a 'game' look was to draw the text into a picture and then convert to a texture for display. It actually works rather well.

It looks like I might have to update the existing plugin for Universal Binary and worry about windows another day. We tried updating the plugin but endian issues got the better of us so I may ask for some help here even if it is C (mainly << and >> issues and getting the alpha value into the correct position).

regards,

_________________
Peter
http://www.fracturedSoftware.com
Rondo - Midi made easy.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 23, 2006 3:17 pm 
Offline

Joined: Fri Sep 30, 2005 6:55 pm
Posts: 1522
If you just need to draw text to an OpenGL surface, try this old project I made:

http://waterfallsw.com/~mike/Classes/GLView2D.zip

It's pretty ugly the way it handles things, but I wanted to post it just in case it helps in any way.

_________________
Those who can, do. Those who can't, make excuses.


Top
 Profile  
Reply with quote  
 Post subject: Re: Converting REALbasic Picture to OpenGL texture?
PostPosted: Sun Aug 07, 2011 12:17 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 6:24 pm
Posts: 99
Location: USA
2 questions here:
To add Alpha to the texture I just add another byte per pixel?
How do I get OpenGL and my memory block to connect? How do I get the pixel data into OpenGL?

_________________
Sole Proprietor
10101 Software
http://www.10101software.co.nr/
RB 2011r4.3, MBS 12.4


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group