Dark Bit Factory &  Gravity

Dark Bit Factory & Gravity

  • July 30, 2010 *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Pages: 1 2 [3]   Go Down

Author Topic: OpenGL framebuffer library  (Read 5211 times)

0 Members and 1 Guest are viewing this topic.

Stonemonkey

  • Pentium
  • *****
  • Karma: 88
  • Offline Offline
  • Posts: 1164
    • 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;

Logged

Phoenix

  • C= 64
  • **
  • Karma: 4
  • Offline Offline
  • Posts: 99
    • 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.
Logged

Stonemonkey

  • Pentium
  • *****
  • Karma: 88
  • Offline Offline
  • Posts: 1164
    • 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.
Logged

Phoenix

  • C= 64
  • **
  • Karma: 4
  • Offline Offline
  • Posts: 99
    • 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;
Logged

Stonemonkey

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

0xff000000

Logged

Jim

  • ADMIN
  • Senior Member
  • ********
  • Karma: 325
  • Offline Offline
  • Posts: 4676
    • 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
Logged

ninogenio

  • Sponsor
  • Pentium
  • *******
  • Karma: 88
  • Offline Offline
  • Posts: 1230
    • 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 ;
Logged

Jim

  • ADMIN
  • Senior Member
  • ********
  • Karma: 325
  • Offline Offline
  • Posts: 4676
    • 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
Logged

ninogenio

  • Sponsor
  • Pentium
  • *******
  • Karma: 88
  • Offline Offline
  • Posts: 1230
    • 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!
Logged

Allosentient

  • ZX 81
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 5
    • 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!
Logged

stormbringer

  • Time moves by fast, no second chance
  • Contributing Author
  • Amiga 1200
  • ******
  • Karma: 73
  • Offline Offline
  • Posts: 450
    • View Profile
    • WWW
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.
Logged
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

benny!

  • Senior Member
  • ******
  • Karma: 174
  • Offline Offline
  • Posts: 3424
  • in this place forever!
    • View Profile
    • WWW
Re: OpenGL framebuffer library
« Reply #51 on: July 05, 2009 »
@Stormbringer:
Thanks for pointing that out!
Logged
[ microBLOG - PHLOCKS - LABS - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
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...
Logged

Clyde

  • A Little Fuzzy Wuzzy
  • Contributing Author
  • Senior Member
  • ******
  • Karma: 71
  • Offline Offline
  • Posts: 6965
    • View Profile
Re: OpenGL framebuffer library
« Reply #53 on: September 07, 2009 »
How is this going?
Logged
If only I knew then what I know now.

rbz

  • MOD
  • Senior Member
  • *******
  • Karma: 272
  • Offline Offline
  • Posts: 2133
    • View Profile
    • WWW
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.
Logged
rbz ^ Codigos

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
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.
Logged

Pages: 1 2 [3]   Go Up
 

 

B l a c k R a i n V.2 by C r i p

Page created in 0.247 seconds with 20 queries.