Author Topic: [C++] Opengl & bitmaps from memory  (Read 13774 times)

0 Members and 1 Guest are viewing this topic.

Offline AnimalMother

  • btst #6,$bfe001
  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
[C++] Opengl & bitmaps from memory
« on: July 03, 2008 »
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?

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: [C++] Opengl & bitmaps from memory
« Reply #1 on: July 03, 2008 »
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

Offline AnimalMother

  • btst #6,$bfe001
  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #2 on: July 03, 2008 »
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?

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: [C++] Opengl & bitmaps from memory
« Reply #3 on: July 03, 2008 »
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

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: [C++] Opengl & bitmaps from memory
« Reply #4 on: July 03, 2008 »
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

Offline AnimalMother

  • btst #6,$bfe001
  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #5 on: July 03, 2008 »
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   ::)

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: [C++] Opengl & bitmaps from memory
« Reply #6 on: July 03, 2008 »
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

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: [C++] Opengl & bitmaps from memory
« Reply #7 on: July 04, 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:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: [C++] Opengl & bitmaps from memory
« Reply #8 on: July 04, 2008 »
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

Offline AnimalMother

  • btst #6,$bfe001
  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #9 on: July 04, 2008 »
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  ;)

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #10 on: July 04, 2008 »
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

Offline AnimalMother

  • btst #6,$bfe001
  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #11 on: July 31, 2008 »
Now I´am stuck again.  :(
Can someone provide me with a sample for drawing text with a bitmap font like the amiga bitmap fonts?

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [C++] Opengl & bitmaps from memory
« Reply #12 on: July 31, 2008 »
What's wrong with Nehe's ?
Challenge Trophies Won:

Offline AnimalMother

  • btst #6,$bfe001
  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #13 on: July 31, 2008 »
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.
« Last Edit: July 31, 2008 by AnimalMother »

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [C++] Opengl & bitmaps from memory
« Reply #14 on: July 31, 2008 »
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:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: [C++] Opengl & bitmaps from memory
« Reply #15 on: July 31, 2008 »
Take a look at this tutorial, more specifically at "BuildFont" and "glPrint" subroutines, you can easily adapt it to your program.
Challenge Trophies Won:

Offline AnimalMother

  • btst #6,$bfe001
  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #16 on: August 01, 2008 »
Thanks. Now things become clearer  ;D

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #17 on: August 24, 2009 »
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:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #18 on: August 24, 2009 »
At the command prompt, type:
Code: [Select]
bin2c inputfile output.cpp
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [C++] Opengl & bitmaps from memory
« Reply #19 on: August 25, 2009 »
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: