Author Topic: OpenGL framebuffer library  (Read 27578 times)

0 Members and 1 Guest are viewing this topic.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
OpenGL framebuffer library
« on: September 23, 2006 »
I started this new topic to post the development status of opengl ptc and stop hijacking Clyde topics :)

I'm using this section since it's coded in C/C++, anyway you will able to use this library with Freebasic,C/C++ and others programing language capable to link with static library.  Â Btw the main idea was to code it for Freebasic and there is a example for it in the ptc.rar file.

Jim coded the main part of the library and I'm trying to help finish it  ;)

Added:
  • Fullscreen option
  • Key_Test example
  • Mouse x,y position and left,right button support, see "Mouse_Test.bas" example
  • Disable screensaver while ptc is running




« Last Edit: September 26, 2006 by Rbraz »
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: OpenGL framebuffer library
« Reply #1 on: September 24, 2006 »
Looking forward to seeing a final version of this.
By the way Rbraz, are you taking requests for this library? I'd love to add a wish list.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: OpenGL framebuffer library
« Reply #2 on: September 24, 2006 »
@Rbraz:

Sounds interesting. Do you have any speed tests about the OpenGL glDrawPixels command
compared to e.g. DirectX or direct memory accessing ?
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL framebuffer library
« Reply #3 on: September 24, 2006 »
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

Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
Re: OpenGL framebuffer library
« Reply #4 on: September 24, 2006 »
Quote
Do you have any speed tests about the OpenGL glDrawPixels command
compared to e.g. DirectX or direct memory accessing ?
Not yet, but as Jim said it should be fast like DirectDraw framebuffer.

Quote
By the way Rbraz, are you taking requests for this library? I'd love to add a wish list.
If there's anything that I can help, just ask. Btw this version is the most tiny and functional possible, and capable to replace the original tinyptc.


Check out the new version, I've added a fullscreen option and an example to how to use keyboard check in to your programs.
 :cheers:
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: OpenGL framebuffer library
« Reply #5 on: September 24, 2006 »
It works really well Rbraz. I love it, it's great that you have included some functions that will help to get people started and that they behave like Blitz.

I'm not sure if I would find these functions useful myself as I'd prefer to resource my media into the program to get it one filed but I am glad that you have included them as it gives a great example for people who are making the step from Blitz to FB.

The PTC_SETFLIP command is wicked. Love it, it works brilliantly.

I see

while(1)
...
wend

I have to check this. how is this relating to the keyboard? Is that check a part of the lib?
So if I want to have a demo that exits on escape, that's all I have to do? :)

Great that it runs without any modifications to the original install of FB.

Now, to make this really kickass, here are a few things that I would do.

1: a screendim command.
as this is using opengl now, how about using a blank sprite as a means of dimming the screen?
The dim command could be;

dim (&HFFFFFF , 255) Where the colour is the colour of the sprite and the following number is the opacity of it. The sprite could just be drawn over the top of the screen. That would really rock.

Maybe access Opengl's lines,polygons and gourad triangles?

I don't know how practical these suggestions would be to get them to work in conjunction with a screen buffer.

GETMOUSEX
GETMOUSEY
GETLEFTBUTTON
GETRIGHTBUTTON

Commands for reasing the mouse.

As far as it is at the moment though, it is something to be proud of. I'll definately be using it :)

Shockwave ^ Codigos
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
Re: OpenGL framebuffer library
« Reply #6 on: September 24, 2006 »
@SW: added mouse support as you wish.

About "screendim command", I don't know exactly what do you mean, maybe Jim can help.

Quote
I have to check this. how is this relating to the keyboard? Is that check a part of the lib?
The library check for Escape key and exit if it was pressed.
Btw, for the main loop, I take a look at it, and it's more safe if you do it like this:
(Include windows.bi)

Code: [Select]
while(GetAsyncKeyState(VK_ESCAPE)<>-32767)
...
...
wend



Quote
Maybe access Opengl's lines,polygons and gourad triangles?
I'm afraid that this is not possible for now...
« Last Edit: September 24, 2006 by Rbraz »
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: OpenGL framebuffer library
« Reply #7 on: September 24, 2006 »
Works like a charm :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL framebuffer library
« Reply #8 on: September 25, 2006 »
added:
Alt-Enter can now toggle full screen mode.
ptc_openex(title,width, height, fullscreen, refreshrate)
ptc_fullscreen(onoff)

fixed:
Took out the SPI_SETSCREENSAVERACTIVE. This isn't the recommended way of disabling screensavers. Correct way is to handle WM_SYSCOMMAND and WM_POWERBROADCAST messages.
Coming out of fullscreen mode wouldn't reset the display correctly.
vc project file now builds to libptc.a directly.
vc project file now excludes default libraries.

I can't see any reason why you can't use OpenGL commands in your freebasic programs now...just include gl/gl.bi.  If you mess up the view matrices, expect the screen to go funny.  Don't mix ptc_update, just draw things with OpenGL and call ptc_flip().

Would love some requests for features :D

Jim
« Last Edit: September 25, 2006 by Jim »
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
Re: OpenGL framebuffer library
« Reply #9 on: September 25, 2006 »
@Jim: the alt+enter doesn't work for me...

Anyway nice additions, didn't noticed that SPI_SETSCREENSAVERACTIVE isn't the recommended way to disable screensavers, nice one.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL framebuffer library
« Reply #10 on: September 25, 2006 »
Rats.  Any idea why/where it's failing?

As this gets more complicated, we need to add a C program that tests it so you can actually debug it in VC.

Jim
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: OpenGL framebuffer library
« Reply #11 on: September 25, 2006 »
Code: [Select]
int __cdecl ptc_update(const unsigned int *pixels)
{
// process messages
MSG msg;
while (PeekMessage(&msg,gameWindow,0,0,PM_REMOVE))
{
// translate and dispatch
TranslateMessage(&msg);
DispatchMessage(&msg);
}

glDrawPixels(g_w,g_h,GL_BGRA_EXT,GL_UNSIGNED_BYTE,pixels);
ogl_flip();
return PTC_OK;
}


Hi guys, why glDrawPixels?  Can't glTexSubImage2D be used for this?  Oreven gltexImage2d.  Just my thoughts.



« Last Edit: September 25, 2006 by relsoft »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL framebuffer library
« Reply #12 on: September 25, 2006 »
You could use glTexSubImage2D to load the screen data into a next-power-of-2 sized texture you'd previously created.  So you could make a 1024x512 texture for a 640x480 screen.  Then after that you'd have to render a single GL_QUAD to draw the texture to the screen.  That would definitely work.  glDrawPixels moves the image directly to the screen, so you'd think it would be quicker since it involves one less copy of the data.  Lots of glDrawPixels calls are very, very slow on my PC, but doing just one is fast.  I will definitely check this option later on but tbh, it's blazingly quick anyway.  It would certainly make it possible to do all kinds of feedback/motion blur tricks if you could use the last screen output as a texture in a new scene, which would be very cool.

That leads me to another question.  I know dbf is strongly focussed on doing everything in software.  I like that :).  Depending on how much gets added to this lib all kinds of things could be accelerated by OpenGL.  Is that what is wanted from this lib, or just a few special fx?  Perhaps that will require two versions.  A tiny <10Kb lib that does the basic stuff, and a bigger one with all the bells and whistles.  Any comments?

Jim
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL framebuffer library
« Reply #13 on: September 25, 2006 »
Quote
1: a screendim command.
as this is using opengl now, how about using a blank sprite as a means of dimming the screen?

Here's an example of what I mean.  OpenGL allows an offset and a scale to the colours that are uploaded by glDrawPixels or glTex.
At the top of your program add
Code: [Select]
#include "gl/gl.bi"Then, before ptc_update() do this
Code: [Select]
glPixelTransferf(GL_RED_SCALE, 0.9)
glPixelTransferf(GL_GREEN_SCALE, 0.5)
glPixelTransferf(GL_BLUE_SCALE, 0.1)

The number is the scale amount for red, green and blue, ranging from 0.0 to 1.0.  Numbers over 1.0 clamp to 1.0 for some other odd fx.  Lots more info here

Jim
Challenge Trophies Won:

Offline MrP

  • Atari ST
  • ***
  • Posts: 176
  • Karma: 18
    • View Profile
Re: OpenGL framebuffer library
« Reply #14 on: September 25, 2006 »
This really is starting to to look like a very cool lib. However I'm going to have to chastise you all for not coming up with it sooner. Maybe before I'd nearly finished writing most of my own stuff that uses GFXLib.... lol... Only kidding guys keep it up going to d/load and give this a whirl tonight when I get in from work.....

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: OpenGL framebuffer library
« Reply #15 on: September 25, 2006 »
i think a tiny version and a delux version might be the way to go!

i had no idea you could alpha pixels like that.hows about using a bit of mmx for 64 bit transfers im guessing you would have to use glteximage2d for mmx though?

i like the idea of using opengl renderd lines and polys. great work guys  :cheers:
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: OpenGL framebuffer library
« Reply #16 on: September 25, 2006 »
I think that 2 versions are needed.
Basically I think that for me, I am going to have to carry on doing softrendered stuff, but not everyone here wants that. This could be a really cool and unique tool that will help a lot of people get into demo programming. Maybe we could start a topic for each with the features that each lib should include?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: OpenGL framebuffer library
« Reply #17 on: September 25, 2006 »
sounds good shockwave!

me personally i dont mind where ever the speed is im there :)
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
Re: OpenGL framebuffer library
« Reply #18 on: September 26, 2006 »
I think that 2 versions are needed. ......
Yeah, I agree with Shockwave  :)
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: OpenGL framebuffer library
« Reply #19 on: September 26, 2006 »
Couldnt you do something similar to how you'd make FB use windowed mode. And have something for example: DEFINE LIBRARY_MODE1
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: