[Patch] Rendering of FreeBasic graphic on OpenGL

General discussion for topics related to the FreeBASIC project or its community.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by coderJeff »

I only made changes to gfxlib source code and fbgfx.bi at the time to use constant names, instead of numeric literals, so it is easier to search for in the source code.

In fbgfx.bi we have these constants added:

Code: Select all

OGL_2D_NONE            = 0
OGL_2D_MANUAL_SYNC     = 1
OGL_2D_AUTO_SYNC       = 2

SET_GL_2D_MODE         = 150
SET_GL_SCALE		     = 151
If someone could write descriptions, they could get added Screencontrol page. In general, the names of constants should be preferred over hard coding the values in source. Should the constant values change for some reason, the symbolic names would still be valid.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

Consistent with the 'ScreenRes' page, I propose to delete the values ​​(in parentheses) of 'what' on the 'ScreenControl' page.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

Help me update the ScreenControl page.
My non-specialist proposal:
  • ..........
    ..........
  • SET_GL_NUM_SAMPLES Sets the number of samples to be used for OpenGL multisampling
    • [IN] param1 samples
  • SET_GL_2D_MODE Sets OpenGL 2D render
    • [IN] param1:
      • OGL_2D_NONE No rendering
        OGL_2D_MANUAL_SYNC Manual rendering (when Flip is called)
        OGL_2D_AUTO_SYNC Automatic rendering
  • SET_GL_SCALE Apply a zoom factor of 2 on OpenGL 2D render (only allowed if OpenGL 2D render mode has yet been set via SET_GL_2D_MODE)
    • [IN] param1:
      • OGL_2D_NONE No rendering
        OGL_2D_MANUAL_SYNC Manual rendering (when Flip is called)
        OGL_2D_AUTO_SYNC Automatic rendering
[edit]
negligible formatting
Last edited by fxm on Mar 10, 2019 7:04, edited 2 times in total.
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by Landeel »

The parameters for SET_GL_SCALE are wrong.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

Landeel wrote:The parameters for SET_GL_SCALE are wrong.
But how to fix this for SET_GL_SCALE?
Should we use only OGL_2D_AUTO_SYNC (or OGL_2D_NONE to cancel any rendering)?

2nd proposal (I have at least the merit of proposing something):
  • ..........
    ..........
  • SET_GL_NUM_SAMPLES Sets the number of samples to be used for OpenGL multisampling
    • [IN] param1 samples
  • SET_GL_2D_MODE Sets OpenGL 2D render
    • [IN] param1:
      • OGL_2D_NONE No rendering
        OGL_2D_MANUAL_SYNC Manual rendering (when Flip is called)
        OGL_2D_AUTO_SYNC Automatic rendering
  • SET_GL_SCALE Apply a zoom factor of 2 on OpenGL 2D render (only allowed if OpenGL 2D render mode has yet been activated via SET_GL_2D_MODE)
    • [IN] param1:
      • OGL_2D_AUTO_SYNC Automatic rendering
        (OGL_2D_NONE No more rendering)
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by Landeel »

It has nothing to do with sync. It's about scaling.
Either it should take a numeric value or we need new constants.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

Landeel wrote:It has nothing to do with sync. It's about scaling.
Either it should take a numeric value or we need new constants.
Sorry but I did not play enough with it!

3rd proposal:
  • ..........
    ..........
  • SET_GL_NUM_SAMPLES Sets the number of samples to be used for OpenGL multisampling
    • [IN] param1 samples
  • SET_GL_2D_MODE Sets OpenGL 2D render
    • [IN] param1:
      • OGL_2D_NONE No rendering
        OGL_2D_MANUAL_SYNC Manual rendering (when Flip is called)
        OGL_2D_AUTO_SYNC Automatic rendering
  • SET_GL_SCALE Apply a zoom factor on OpenGL 2D render (only allowed if OpenGL 2D render mode has yet been activated via SET_GL_2D_MODE)
    • [IN] param1 Zoom factor (0: No rendering)
  • A limit for the value of the 'Zoom factor' (or depends on the hardware)?
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by Landeel »

I think the only acceptable values are 0 for 1:1 scaling, and 1 for 2:1 scaling, but im not sure.
I don't have my pc right now.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

I tried on my PC. It works with a zoom factor from 1 to 14!
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by coderJeff »

fxm wrote:Consistent with the 'ScreenRes' page, I propose to delete the values ​​(in parentheses) of 'what' on the 'ScreenControl' page.
Sounds good to me.

User's probably will want to know:
coderJeff wrote:What can be or needs to be set-up before Screen/ScreenRes?
What can be changed after Screen/ScreenRes? To what effect?
This comment seems important:
angros47 wrote:It is supposed to be a 1. Wait... in your test, you put ScreenControl after ScreenRes, you should put it BEFORE.
(ScreenControl is also used to set which driver will be used, so it has to be used before setting the graphic mode)
fxm, thanks for testing and updating the manual.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

At ScreenControl documentation page, there is already a tag (*) that denotes the only operations that are allowed while a graphics mode has not yet been set via Screen (Graphics) or ScreenRes.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

KeyPgScreencontrol → fxm [Suppressed the function codes values - Added a set operation: OpenGL 2D render]

[edit]
I added the tag (**) that indicates the operations to be performed before the graphics mode is set via Screen (Graphics) or ScreenRes
Last edited by fxm on Mar 10, 2019 21:15, edited 2 times in total.
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by Landeel »

Nice, thank you!
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

fxm wrote:I tried on my PC. It works with a zoom factor from 1 to 14!
@angros47,
What do you think about a possible zoom factor limitation value to document?
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by dodicat »

Are there instructions elsewhere because I cannot get this to work yet (fb 1.06)
(Been trying for a while)
I just want a cube in gl and some graphics in gfx.

Code: Select all

 #Include Once "GL/glu.bi"
#include once "fbgfx.bi"
using fb

screencontrol SET_GL_2D_MODE ,OGL_2D_MANUAL_SYNC
'screencontrol SET_GL_SCALE,1

Dim Shared As Integer xres,yres
Screenres 1024,512,32,,GFX_OPENGL
width 1024\8,512\16 'larger fonts
Screeninfo xres,yres

Function Regulate(Byval MyFps As long,Byref fps As long) As long
    Static As Double timervalue,lastsleeptime,t3,frames
    Dim As Double t=Timer
    frames+=1
    If (t-t3)>=1 Then t3=t:fps=frames:frames=0
    Dim As long sleeptime=lastsleeptime+((1/myfps)-T+timervalue)*1000
    If sleeptime<1 Then sleeptime=1
    lastsleeptime=sleeptime
    timervalue=T
    Return sleeptime
End Function

Sub glsetup 
    glShadeModel(GL_SMOOTH)                 ' Enables Smooth Color Shading
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) 
    glBlendFunc(GL_ONE,GL_ONE)
    glEnable GL_ALPHA
    glEnable GL_BLEND
    glViewport(0, 0, xres, yres)       ' Set the viewport
    glMatrixMode(GL_PROJECTION)        ' Change Matrix Mode to Projection
    glLoadIdentity                     ' Reset View
    gluPerspective(45.0, xres/yres, 1.0, 100.0) 
    glMatrixMode(GL_MODELVIEW)         ' Return to the modelview matrix
    glLoadIdentity                     '  Reset View
    glclearcolor .2,0,0,1
End Sub

'Rotate and draw the cube with texturing on each face
Sub DrawGlCube(Byref rotangle As Single)
    glLoadIdentity() 
    glTranslatef(0,0,-5)
    glRotatef(rotangle,1,.5,.25)           ' Rotate 
    glBegin(GL_QUADS)
    
    glcolor3ub 255,0,0
    glVertex3f( 1.0, 1.0,-1.0)            ' Top right of the quad (top)
    glVertex3f(-1.0, 1.0,-1.0)            ' Top left of the quad (top)
    glVertex3f(-1.0, 1.0, 1.0)            ' Bottom left of the quad (top)
    glVertex3f( 1.0, 1.0, 1.0)            ' Bottom right of the quad (top)
    
    glcolor3ub 255,100,0
    glVertex3f( 1.0,-1.0, 1.0)            ' Top right of the quad (bottom)
    glVertex3f(-1.0,-1.0, 1.0)            ' Top left of the quad (bottom)
    glVertex3f(-1.0,-1.0,-1.0)            ' Bottom left of the quad (bottom)
    glVertex3f( 1.0,-1.0,-1.0)            ' Bottom right of the quad (bottom)
  
    glcolor3ub 255,0,255
    glVertex3f( 1.0, 1.0, 1.0)            ' Top right of the quad (front)
    glVertex3f(-1.0, 1.0, 1.0)            ' Top left of the quad (front)
    glVertex3f(-1.0,-1.0, 1.0)            ' Bottom left of the quad (front)
    glVertex3f( 1.0,-1.0, 1.0)            ' Bottom right of the quad (front)
    
    glcolor3ub 0,0,200
    glVertex3f( 1.0,-1.0,-1.0)            ' Bottom left of the quad (back)
    glVertex3f(-1.0,-1.0,-1.0)            ' Bottom right of the quad (back)
    glVertex3f(-1.0, 1.0,-1.0)            ' Top right of the quad (back)
    glVertex3f( 1.0, 1.0,-1.0)            ' Top left of the quad (back)
    
    glcolor3ub 0,255,0
    glVertex3f(-1.0, 1.0, 1.0)            ' Top right of the quad (left)
    glVertex3f(-1.0, 1.0,-1.0)            ' Top left of the quad (left)
    glVertex3f(-1.0,-1.0,-1.0)            ' Bottom left of the quad (left)
    glVertex3f(-1.0,-1.0, 1.0)            ' Bottom right of the quad (left)
    
    glcolor3ub 255,0,100
    glVertex3f( 1.0, 1.0,-1.0)            ' Top right of the quad (right)
    glVertex3f( 1.0, 1.0, 1.0)            ' Top left of the quad (right)
    glVertex3f( 1.0,-1.0, 1.0)            ' Bottom left of the quad (right)
    glVertex3f( 1.0,-1.0,-1.0)
    glend
End Sub
'=============== for ball only  =========
type pt
        as long x=100,y=100
        as single dx,dy
        as long kx,ky
    end type
sub ball()
    static as pt b
    static as long kx=1,ky=1
    b.dx=8
    b.dy=6.5
    b.x+=b.dx*kx:b.y+=b.dy*ky
    if b.x<50 or b.x>xres-50 then kx=-kx
    if b.y<50 or b.y>yres-50 then ky=-ky
    circle (b.x,b.y),50,rgb(0,100,255),,,,f
    end sub
'===============

'NOW START OPENGL
glsetup

Dim As Single angle
dim as long fps
Do
    angle=angle+1
    glClear(GL_COLOR_BUFFER_BIT)
  
     glEnable (GL_CULL_FACE)
     DrawGlcube(angle)
     gldisable (GL_CULL_FACE)
  
      cls
      glcolor3ub 255,255,255  'reset
    ball()
    draw string (20,20),"OpenGL cube with FreeBASIC ball and text",rgb(255,100,0)
    draw string (30,50),"Frames per second  = " &fps,rgb(255,255,255)
   
    Flip
    Sleep regulate(30,fps),1
Loop Until Inkey=Chr(27)

    
I see the cube for an instant, then it is gone.
If the new screencontrol bit is commented out I see the cube.
Post Reply