Author Topic: OpenGL framebuffer library  (Read 32916 times)

0 Members and 7 Guests are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: OpenGL framebuffer library
« Reply #40 on: October 15, 2007 »
1) unsigned int is the correct type for pixels (shifting is ill-defined for signed values - who knew that eh?)
oops, I should've.

2) the type cast can hide errors
cheers Jim, hadn't thought of it that way.

3) by using sizeof *buffer instead of sizeof(int) you remove one more place that you might need to change the code.
Hadn't thought of that either.


Code: [Select]
unsigned int *buffer = new unsigned int [RES_X*RES_Y];
Looks better but is there any difference in how it allocates the memory?


There's sometimes different formats used but tinyptc uses this (although I'm not sure if some different graphics cards need it in a different format):
Code: [Select]

return (alpha<<24)|(red<<16)|(green<<8)|blue;


Offline Phoenix

  • C= 64
  • **
  • Posts: 99
  • Karma: 4
    • View Profile
Re: OpenGL framebuffer library
« Reply #41 on: October 15, 2007 »
I solved it :) This is how it's done:
Code: [Select]
//-----------------------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------------------
int __cdecl ptc_torgb(unsigned char red, unsigned char green, unsigned char blue)
{
return 0xFFFFFFFFFF000000|(((red<<8)+green)<<8)+blue;
}

However, I have no idea how it works :P I was testing in the windows calculator converting various ARGB values into hex, and lots of F:s appeared in front of the colors.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: OpenGL framebuffer library
« Reply #42 on: October 15, 2007 »
If your ints are 32 bit then the first 8 Fs shouldn't make any difference, as for the rest of it, in this case using + (add) is the same as using | (or) because each of the 8 bit colour values don't overlap and both ways have the effect of writing the 8 bit value into the appropriate 8 bits of the result, and the red bits are shifted by 8 bits twice which is the same as shifting by 16 bits.

It used to be the case that OR was faster than ADD but I don't think it makes any difference any more.

Offline Phoenix

  • C= 64
  • **
  • Posts: 99
  • Karma: 4
    • View Profile
Re: OpenGL framebuffer library
« Reply #43 on: October 15, 2007 »
You're right :) It can be shortened to:
Code: [Select]
return 0xFF+(((red<<8)+green)<<8)+blue;

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: OpenGL framebuffer library
« Reply #44 on: October 15, 2007 »
IF you want to set the alpha bits, it should be

0xff000000


Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL framebuffer library
« Reply #45 on: October 16, 2007 »
Quote
Code: [Select]
unsigned int *buffer = new unsigned int [RES_X*RES_Y];
Looks better but is there any difference in how it allocates the memory?
Yes, you can overload the 'new' and 'new []' operators in C++ so it calls something else.  It can also throw exceptions on failure.
The actual memory still comes form the same place though, but you mustn't mix malloc/free with new/delete.
In this case you'd want
Code: [Select]
delete [] buffer;

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: OpenGL framebuffer library
« Reply #46 on: October 19, 2007 »
jim can the above be done in these conditions in cpp.

typedef struct {
       
          float x;
          float y;
          float z;
}vertex;

typedef struct {
           
           vertex * myvertex;
           blah ..
           blah ..
} entity

entity * myentity;

myentity = new entity;
myentity->myvertex = new vertex[10] ;

delete [] myenetity->myvertex ;
delete [] myentity ;
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL framebuffer library
« Reply #47 on: October 19, 2007 »
The last line should just be
Code: [Select]
delete myentity;
It's not an array so you don't need the []

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: OpenGL framebuffer library
« Reply #48 on: October 19, 2007 »
ah cool so it can be used in exactly the same way as malloc and free cheers!
Challenge Trophies Won:

Offline Allosentient

  • ZX 81
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
Re: OpenGL framebuffer library
« Reply #49 on: November 11, 2008 »
Whatever the DirectX speed is, OpenGl will come out pretty much the same.  Somehow you have to hammer 640x480x4x60 bytes per second up to the gfx card.  That's around 80Mb/s, which is a lot.

Jim



I know this is an old post, but wanted to contribute.  I noticed that DrawPixels was mentioned right before this post.  The goal of using the graphics card is to have the graphics card procedurally create the pixels you are talking about here.  You are not sending 80 mb/sec to the graphics card, you are sending a set of instructions for the graphics card to process on the side.  This is why the use of DrawPixels isn't really recommended for the entire screen.

I am not an expert here by any means so please correct me if I am wrong!

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: OpenGL framebuffer library
« Reply #50 on: July 03, 2009 »
I also noticed that a lot of OpenGL framebuffer libs here use DrawPixels. This has been marked as deprecated in OpenGL 3.0 (and potentially removed in a few years). It's a very old method of updating stuff in the OpenGL frame buffer and has been left out of hardware acceleration by most drivers (especially on laptops and small systems). For future proof, hardware accelerated bitmap transfers, you should always create textures with glTexImage1D/2D/3D and update the texture buffer with glTexSubImage1D/2D/3D.

Textures can then be used in shaders, can be used for texturing primitives and benefit from the latest OpenGL extensions and of course hardware acceleration.
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 benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: OpenGL framebuffer library
« Reply #51 on: July 05, 2009 »
@Stormbringer:
Thanks for pointing that out!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: OpenGL framebuffer library
« Reply #52 on: July 07, 2009 »
Quote
you should always create textures with glTexImage1D/2D/3D and update the texture buffer with glTexSubImage1D/2D/3D.
That's essentially what I was doing here, but unluckily support for non-power-of-two textures isn't quite were I expected it to be.
So for a 640x480 image you upload 1024x512 which leads the concept ad absurdum...
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: OpenGL framebuffer library
« Reply #53 on: September 07, 2009 »
How is this going?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: OpenGL framebuffer library
« Reply #54 on: September 08, 2009 »
Status = Closed.

:) We stopped working on it after having incompatibilities (slow down) on some PC config, and then tinyptc_ext born.
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: OpenGL framebuffer library
« Reply #55 on: September 08, 2009 »
Another option is to use Direct3D instead as most modern chipsets aim to be compatible with Windows Vista (requiring to support per-pixel floating-point processing) but still fail to read a texel from an arbitrary sized texture using OpenGL.
Challenge Trophies Won: