• Welcome to Dark Bit Factory & Gravity.
 

[C++] Opengl & bitmaps from memory

Started by AnimalMother, July 03, 2008

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

AnimalMother

Hi folks.
I would like to include gfx stuff in the executeable but I donÃ,´t want to do it with resources.
Is it possible?

stormbringer

Hi AnimalMother!

just use the small attached toolI made to turn your data (gfx/music/etc) into an array of bytes usable in C/C++. just put your "byte" data type and array name. Also this tool has a small bug as it adds the end of file code (-1) at the end of the array (0xffffffff value at the very end of the array).

you may need to change the settings of your compile to give it more memory for the precompiler headers (if you include large arrays of data).

Good luck!
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

AnimalMother

Yes this tool comes quite handy, but for example OpenGl requires a diffrent gfx format. I read about the raw format or do I have to include a bmp and convert it?

stormbringer

OpenGL only takes RAW data from memory => the tool I gave you converts any file into an array of bytes.

If you have BMP files, consider converting them with Photoshop, or whatever freeware tool into RAW format => which is basically only the bytes containing the data, no metadata, no formatting, etc.

Use this tool: http://www.xnview.com/ (XNview, freeware) to convert your files into RAW data. then my tool to convert the RAW data into an array of bytes for C/C++. there you go.

BTW, why do people (including me?) write RAW with capital letters??? it's not an acronym at all. it should be raw files (as raw fish). This means bytes containing the data only, no metadata and special formatting.
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

stormbringer

Of course make sure your raw file has the same format as OpenGL expects it. This means that if you give OpenGL the data as RGB 8bit, then your raw file should have RGB pixels (interleaved format) in 8bits. This means 1byte per channel the following order:

1 byte red, 1 byte green, 1 byte blue, 1 byte red, 1 byte green, 1 byte blue, 1 byte red, 1 byte green, 1 byte blue, 1 byte red, 1 byte green, 1 byte blue, ...
...
1 byte red, 1 byte green, 1 byte blue, 1 byte red, 1 byte green, 1 byte blue, 1 byte red, 1 byte green, 1 byte blue

ordering pixels from top to bottom or bottom to top, or right to left, etc does not make a difference since you can change that very easily with OpenGL. Just order the pixels in a way that makes it easy for you to understand/compute U/V coordinates for your texture. Personally I prefer left to right, top to bottom. More logical to me. It's a question of taste.

Before you jump into daisy-chaining conversions etc, try to update your texxture with the contents of a buffer in memory. Once you have done that, go to the conversion step. In order to simplify debugging, try with some stupid patern that you can understand, such as a gradient, a 1-pixel black & white checkerboard, etc. Make sure this works and then try with a picture.

The reason I'm saying this it's because OpenGL is a state machine. If you do not set your state correctly before your draw/paint, then the results may not be the ones you have expected.

So make sure the basics work first.





We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

AnimalMother

Ahh ok IÃ,´ll give it a try. Thank you very much !!!
BTW: Maybe RAW looks more dangerous than raw. Or maybe capitals are more 3l337 style   ::)

stormbringer

You are welcome!

Of course some stupid marketing poeple have invented the RAW format name to designate the native file formats of their still picture/motion picture cameras.

Of course this is bad becase these formats are not raw, they have a specific format and contain the camera metadata. However "most" of the time the image data is stored in the file as it comes off the camera CCD... anyway.
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Rbz

Quote from: stormbringer on July 03, 2008
just use the small attached toolI made to turn your data (gfx/music/etc) into an array of bytes usable in C/C++. just put your "byte" data type and array name. Also this tool has a small bug as it adds the end of file code (-1) at the end of the array (0xffffffff value at the very end of the array).
@stormbringer: try this one (attached), there's no bug in it  :)

Challenge Trophies Won:

stormbringer

Thanks mate! you are correcting all my bugs these days ;)
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

AnimalMother

Now, it works !

BTW: I found another tool that does the same but automatically adds array type & name and the size. Just for the lazy ones like me  ;)

energy

Hi
another way is to use Jim's DirectX LOader (http://dbfinteractive.com/index.php?topic=2760.0)
and use that returned mem and generate an OPENGL- texture in BGRA-Format.
Its very small, but only for use under Windows.


coding: jwasm,masm
hobby: www.scd2003.de

AnimalMother

Now I´am stuck again.  :(
Can someone provide me with a sample for drawing text with a bitmap font like the amiga bitmap fonts?

hellfire

Challenge Trophies Won:

AnimalMother

#13
Nothing except it uses the standard system fonts. I would like to use a custom font which is stored in a picture for example. Like this one attached.

hellfire

If you already have a texture with the required characters, all you need to do is to draw a quad with the appropriate texture-coordinates (to get those you just need to map the character's pixel-positions [0..textureSizeInPixels] to 0..1).
Challenge Trophies Won:

Rbz

Take a look at this tutorial, more specifically at "BuildFont" and "glPrint" subroutines, you can easily adapt it to your program.
Challenge Trophies Won:

AnimalMother

Thanks. Now things become clearer  ;D

Clyde

can you give an example of how to use bin2c please?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

At the command prompt, type:

bin2c inputfile output.cpp

Challenge Trophies Won:

Clyde

i tried that, but it wouldnt save the file. maybe a vista thing.
I read a few messages up a bit about specifying the byte and arrayname.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: