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:

How can a fb.image be diplayed in OpenGL?

Post by Boromir »

With point you can get the color value of a pixel of the fb.image but how can It be displayed in openGL?

Code: Select all

#include  "GL/gl.bi"
#include  "GL/glu.bi"
#include "fbgfx.bi"
Screenres 640,480,32,,fb.GFX_OPENGL
Dim as any ptr buffer=imagecreate(640,480,32)
dim as uinteger col
line buffer,(20,20)-(200,200),rgb(40,78,200),bf
for x=0 to 640
     for y=0 to 480
          col=Point(x,y,buffer)
          Pset(x,y),col'----Any Gl equivalent?
     next
next
Last edited by Boromir on May 22, 2017 21:06, edited 3 times in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

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

Post by MrSwiss »

Not certain, but if col = color then: it's definitely NOT an Integer, but a ULong (or UInteger<32>).
Color is always unsigned INT (aka: 32bit). However, I don't know the OpenGL equivalent ...
Btw: Point(x, y) in FB, retrieves Color from specified location, too.
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 »

Thanks, I meant to say point not poke(I don't even know what poke does)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

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

Post by BasicCoder2 »

Boromir wrote:Thanks, I meant to say point not poke(I don't even know what poke does)
Back in the old MSDOS QBASIC days you could poke data directly into a memory location. You could look at this data with a PEEK statement. This data might be an assembler program such as a mouse driver existing as a list of numbers in DATA statements. You could then call that routine from QBASIC.
.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

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

Post by dodicat »

Try this:

Code: Select all

#include "gl/gl.bi"

Screenres 640,480,32,,2',,GFX_OPENGL =2 
Dim as any ptr buffer=imagecreate(640,480,32)

line buffer,(20,20)-(200,200),rgb(40,78,200),bf
circle buffer,(100,100),50,rgb(0,200,0),,,,f
dim as long x,y



#macro GetColor(_x,_y,colour)
    pixel=row+pitch*(_y)+(_x)*4
    (colour)=*pixel
    #endmacro
    
     Dim As Integer pitch
    Dim  As Any Pointer row
    Dim As Ulong Pointer pixel
    Dim As Ulong col
    
  imageinfo buffer,,,,pitch,row  
  
     glortho(0,640,480,0,-1,1)
  do
  glClear (GL_COLOR_BUFFER_BIT) 
    glbegin (gl_points) 
for x=0 to 640
     for y=0 to 480
         GetColor(x,y,col)
         glcolor3ub(Cptr(Ubyte Ptr,@col)[2],Cptr(Ubyte Ptr,@col)[1],Cptr(Ubyte Ptr,@col)[0])
         glvertex2f(x,y)
          ''Pset(x,y),col'----Any Gl equivalent?
     next
Next
glend
Flip
sleep 1,1
loop until len(inkey)

  
You can also attach a freebasic image to any Quad surface.
But I am following up your requirement.
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 »

BasicCoder2 wrote:Back in the old MSDOS QBASIC days you could poke data directly into a memory location. You could look at this data with a PEEK statement. This data might be an assembler program such as a mouse driver existing as a list of numbers in DATA statements. You could then call that routine from QBASIC.
This is off-topic but I'm curious could Peek be used in a similar way as Point to get the color value?
dodicat wrote:Try this
You can also attach a freebasic image to any Quad surface.
But I am following up your requirement.
That's exactly what I wanted.
How does the attach to quad method work? How would it be affected by screen sizes?
Last edited by Boromir on May 22, 2017 22:33, edited 1 time in total.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

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

Post by thesanman112 »

It should scale to the size of quad being drawn.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

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

Post by MrSwiss »

Alternative to dodicats's method:
using a Union, instead of Pointers, to access the Color-Channels (Color-UBytes)

Code: Select all

#include "gl/gl.bi"

Union Colour
    As ULong    clr
    Type
        As UByte b
        As UByte g
        As UByte r
        As UByte a
    End Type
End Union

ScreenRes(640, 480, 32,, 2)',,GFX_OPENGL =2
Dim As Any Ptr  buffer = ImageCreate(640,480,32)

line    buffer, (20, 20)-(200, 200), RGB(40, 78, 200), bf
circle  buffer, (100, 100), 50, RGB(0, 200, 0),,,, f

Dim As Colour   c0

glortho(0, 640, 480, 0, -1, 1)

do
    glClear (GL_COLOR_BUFFER_BIT)
    glbegin (gl_points)
    For x As UInteger = 0 to 640
        for y As UInteger = 0 to 480
            c0.clr = Point(x, y, buffer)
            glcolor3ub(c0.r, c0.g, c0.b)
            glvertex2f(x, y)
        Next
    Next
    glend
    Flip
    Sleep 1,1
loop until len(inkey)
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 »

MrSwiss wrote:Alternative to dodicats's method:
using a Union, instead of Pointers, to access the Color-Channels (Color-UBytes)
I generally use these.

Code: Select all

#define RGBA_R( c ) ( CUInt( c ) Shr 16 And 255 )
#define RGBA_G( c ) ( CUInt( c ) Shr  8 And 255 )
#define RGBA_B( c ) ( CUInt( c )        And 255 )
#define RGBA_A( c ) ( CUInt( c ) Shr 24         )
thesanman112 wrote:It should scale to the size of quad being drawn.
What I mean is that if the quad is say 640x640, what happens on a screenres of 640x480. Rescaling, squashing or clipping?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

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

Post by MrSwiss »

Boromir wrote:I generally use these.

Code: Select all

#define RGBA_R( c ) ( CUInt( c ) Shr 16 And 255 )
#define RGBA_G( c ) ( CUInt( c ) Shr  8 And 255 )
#define RGBA_B( c ) ( CUInt( c )        And 255 )
#define RGBA_A( c ) ( CUInt( c ) Shr 24         )
With the Union (as well as with pointer access), no bit-shifting required.
Aka: less friction, more speed ...
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 »

MrSwiss wrote:With the Union (as well as with pointer access), no bit-shifting required.
Aka: less friction, more speed ...
Thanks, I'll switch to using that from now on then.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

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

Post by thesanman112 »

Boromir, are you trying to do graphic primitives with opengl? There is or use to be a good help file for opengl,
I believe it was a wikki...there are alot of primitives like quad, sphere, cylinder, if your just going to use qbasic drawing primitives then all full functioallity exists just like opengl primitives.
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:Boromir, are you trying to do graphic primitives with opengl? There is or use to be a good help file for opengl,
I believe it was a wikki...there are alot of primitives like quad, sphere, cylinder, if your just going to use qbasic drawing primitives then all full functioallity exists just like opengl primitives.
Like I said in the OP I want to use the freebasic image format with OpenGl. This allows me to use fbgfx in an OpenGL window, making it easy to port my previous code to render in openGL.
dodicat wrote:Try this:

Code: Select all

#include "gl/gl.bi"

Screenres 640,480,32,,2',,GFX_OPENGL =2 
Dim as any ptr buffer=imagecreate(640,480,32)

line buffer,(20,20)-(200,200),rgb(40,78,200),bf
circle buffer,(100,100),50,rgb(0,200,0),,,,f
dim as long x,y



#macro GetColor(_x,_y,colour)
    pixel=row+pitch*(_y)+(_x)*4
    (colour)=*pixel
    #endmacro
    
     Dim As Integer pitch
    Dim  As Any Pointer row
    Dim As Ulong Pointer pixel
    Dim As Ulong col
    
  imageinfo buffer,,,,pitch,row  
  
     glortho(0,640,480,0,-1,1)
  do
  glClear (GL_COLOR_BUFFER_BIT) 
    glbegin (gl_points) 
for x=0 to 640
     for y=0 to 480
         GetColor(x,y,col)
         glcolor3ub(Cptr(Ubyte Ptr,@col)[2],Cptr(Ubyte Ptr,@col)[1],Cptr(Ubyte Ptr,@col)[0])
         glvertex2f(x,y)
          ''Pset(x,y),col'----Any Gl equivalent?
     next
Next
glend
Flip
sleep 1,1
loop until len(inkey)

  
You can also attach a freebasic image to any Quad surface.
But I am following up your requirement.
Would the Quad method be faster? I noticed this is pretty slow.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

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

Post by thesanman112 »

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...
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

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

Post by thesanman112 »

I should also mention i remember certain vertex calls are crappy in opengl. Why do you want to use opengl? For 3d rendering? Quickest way is with triangles.
Post Reply