How can a fb.image be diplayed in OpenGL?

New to FreeBASIC? Post your questions here.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: How can a fb.image be diplayed in OpenGL?

Post by Boromir »

thesanman112 wrote:Without getting to deep into it....there are certain opengl functions that are indeed slower than qb rendering was/is. Mind you, i havent looked at your cod posted either...
The speed of OpenGL is Dependant on the Users Graphics card but nowadays just about any card will outperform FBgfx. My goal here isn't to obtain that speed benefit but rather to use my Fbgfx programs in OpenGL without too much code rewriting.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: How can a fb.image be diplayed in OpenGL?

Post by thesanman112 »

Can you get rid of the macro? Just put the point function in the loop. It should run faster then.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: How can a fb.image be diplayed in OpenGL?

Post by Boromir »

thesanman112 wrote:Can you get rid of the macro? Just put the point function in the loop. It should run faster then.
Point and Pset are very slow. For speed it's better to use a macro.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: How can a fb.image be diplayed in OpenGL?

Post by thesanman112 »

Pixel is whats in your macro, i couldnt recall sorry.
In any case, i know what you mean about using opengl,
But dont the fb primitives draw by what screen type is called? Im trying to remember exactly.what method does fbgfx use to perform rendering to screen?
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How can a fb.image be diplayed in OpenGL?

Post by dodicat »

You could try this method to display an image:

Code: Select all

#include "gl/gl.bi"
#Include "gl/glext.bi"
#Include "fbgfx.bi"

Screenres 1024,512,32,,FB.GFX_OPENGL 
Dim as any ptr buffer=imagecreate(1024,512,32)
  glortho(0,1024,512,0,-1,1)
line buffer,(20,20)-(200,200),rgb(40,78,200),bf
circle buffer,(100,100),50,rgb(0,200,0),,,,f
Draw String buffer,(500,300),"Hello",RGB(0,0,0)

Function settexture(image As Any Ptr) As gluint
    Dim As gluint texture
    glGenTextures(1, @texture)
    glBindTexture( GL_TEXTURE_2D, texture )
    glTexImage2d( GL_TEXTURE_2D, 0, GL_RGBA, Cast(fb.image Ptr, image)->Width, Cast(fb.image Ptr, image)->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, image+Sizeof(fb.image) )
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST )
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST )
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
    Return texture
End Function
sub background
    glBegin(GL_QUADS)
    glcolor3f(1,0,0)
    glTexCoord2f( 0,0 )
    glvertex2f(0,0)
    glTexCoord2f( 0,1 )
    glvertex2f(0,512)
    glTexCoord2f( 1,1 )
    glvertex2f(1024,512)
    glTexCoord2f( 1,0 )
    glvertex2f(1024,0)
    glend
end Sub

settexture(buffer)
glEnable( GL_TEXTURE_2D )


  
   
  do
  glClear (GL_COLOR_BUFFER_BIT) 
  background
Flip
sleep 1,1
loop until len(inkey)
glDisable( GL_TEXTURE_2D )
ImageDestroy (buffer)
  
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: How can a fb.image be diplayed in OpenGL?

Post by Boromir »

When adding "settexture(buffer)" to the main loop, the program (after running for a while) lags up?

Code: Select all

do
settexture(buffer)
glClear (GL_COLOR_BUFFER_BIT)
background
Flip
sleep 1,1
loop until len(inkey)
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How can a fb.image be diplayed in OpenGL?

Post by dodicat »

glgentextures eats memory.
So just do it once in the function settexture.

Code: Select all


#include "gl/gl.bi"
#Include "gl/glext.bi"
#Include "fbgfx.bi"

Screenres 1024,512,32,,FB.GFX_OPENGL 
Dim as any ptr buffer=imagecreate(1024,512,RGB(0,0,0))
  glortho(0,1024,512,0,-1,1)
line buffer,(20,20)-(200,200),rgb(40,78,200),bf
circle buffer,(100,100),50,rgb(0,200,0),,,,f
Draw String buffer,(500,300),"Hello",RGB(0,0,0)

Function settexture(image As Any Ptr) As gluint
    static As gluint texture,s
    If s=0 Then glGenTextures(1, @texture):s=1
    glBindTexture( GL_TEXTURE_2D, texture )
    glTexImage2d( GL_TEXTURE_2D, 0, GL_RGBA, Cast(fb.image Ptr, image)->Width, Cast(fb.image Ptr, image)->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, image+Sizeof(fb.image) )
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST )
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST )
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
    Return texture
End Function
sub background
    glBegin(GL_QUADS)
    glTexCoord2f( 0,0 )
    glvertex2f(0,0)
    glTexCoord2f( 0,1 )
    glvertex2f(0,512)
    glTexCoord2f( 1,1 )
    glvertex2f(1024,512)
    glTexCoord2f( 1,0 )
    glvertex2f(1024,0)
    glend
end Sub

settexture(buffer)
glEnable( GL_TEXTURE_2D )


  
   
  do
  glClear (GL_COLOR_BUFFER_BIT) 
  Circle buffer,(Rnd*1024,Rnd*512),5,RGB(Rnd*255,Rnd*255,Rnd*255),,,,f
  settexture(buffer)
  background
Flip
sleep 1,1
loop until len(inkey)
glDisable( GL_TEXTURE_2D )
ImageDestroy (buffer)
  
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: How can a fb.image be diplayed in OpenGL?

Post by Boromir »

dodicat wrote:glgentextures eats memory.
Ah, yes. Thank you. I should have known to check for something like that. I've had a similar issues with ImageCreate before and I've learned to always check for Imagecreates in loops when this type of problem occurs.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: How can a fb.image be diplayed in OpenGL?

Post by thesanman112 »

Also, to answer your previous question, opengl clips the edges of drawing primitives to visible screen, although there may be other opengl functions that allow different ways of clipping, but basically it cuts off drawing anythimg that falls out of perspective view, and it does work good, meaning there isnt lag in program because your are drawing off screen. I should also mention that you are not really correct about your response of how fast. Certain opengl commands are, and after you experiment and compare you will find that certain commands/functions are slower than others. Furthermore opengl is software rendered, whereas directx is hardware rendering.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: How can a fb.image be diplayed in OpenGL?

Post by Boromir »

thesanman112 wrote:Also, to answer your previous question, opengl clips the edges of drawing primitives to visible screen, although there may be other opengl functions that allow different ways of clipping, but basically it cuts off drawing anythimg that falls out of perspective view, and it does work good, meaning there isnt lag in program because your are drawing off screen. I should also mention that you are not really correct about your response of how fast. Certain opengl commands are, and after you experiment and compare you will find that certain commands/functions are slower than others.
On some very old computers you may be better off with fbgfx software rendering but on my Nvidia GT 710 OpenGl is blazing fast. It doesn't really matter to me though since fbgfx is fast enough for me.
thesanman112 wrote:Furthermore opengl is software rendered, whereas directx is hardware rendering.
That is incorrect. Opengl and DirectX both use Hardware acceleration. I'm not sure If they made a software rendered version of OpenGL. There is a software rendered DirectX but it is extremely slow.

OpenGL was not made to render 2D graphics in the way FBgfx was so FBgfx could probably put pixels on the screen faster than OpenGL.

By the way, I forgot to thank you all for you help. I appreciate it! :)
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: How can a fb.image be diplayed in OpenGL?

Post by thesanman112 »

http://www.freebasic.net/forum/viewtopi ... ct#p136053

boromir, check out this link, its exactly what your looking for i believe.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: How can a fb.image be diplayed in OpenGL?

Post by Boromir »

thesanman112 wrote:http://www.freebasic.net/forum/viewtopi ... ct#p136053

boromir, check out this link, its exactly what your looking for i believe.
Yup, that's exactly what I was looking for. Thanks!
BasicCoder2
Posts: 3955
Joined: Jan 01, 2009 7:03
Location: Australia

Re: How can a fb.image be diplayed in OpenGL?

Post by BasicCoder2 »

Interesting. I started to use SDL years ago with C++ until I stumbled across FreeBasic. I noticed that Toad On Fire uses SDL. I guess it is good to have a widely used library particularly as it supports sound and user control extensions and would be easy then to port from FB to C++.
.
Post Reply