[Patch] Rendering of FreeBasic graphic on OpenGL

General discussion for topics related to the FreeBASIC project or its community.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by fxm »

In addition, the surface taken by the frame (borders and title) is baddly taken into account when the FreeBASIC graphics instructions are drawn in OpenGL mode.
(the plotting appears to have been stretched to the outer limits of the window instead of remaining within the inner limits of the window)
Last edited by fxm on Mar 12, 2019 10:06, edited 2 times in total.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by angros47 »

@fxm
There is no real limitation in my code about the zoom factor. The maximum possible zoom depends on screen resolution, and (I guess) on the OpenGL implementation, so there is no way to document it

@dodicat
the flip command renders the FreeBasic screen on a square over the OpenGL mode, covering everything else. So, if you want to keep the image you have drawn using OpenGL commands (the cube, in your case) you must make the FreeBasic picture transparent, by setting the alpha value of background color to zero, with COLOR ,RGBA(0,0,0,0) (pay attention to the comma before RGBA) and clearing the screen
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by dodicat »

No luck yet angros47.
I have tried
COLOR ,RGBA(0,0,0,0)
cls
all over the place, including just after screenres where it would normally go.
(Also trying an alpha value in my draw string (as an experiment) makes no difference to the text colour).
...
If I create my own texture to an image in a background quad it works fine in a normal opengl screen.
...

Obviously I am missing something.
Sorry to be a pain.
gothon
Posts: 225
Joined: Apr 11, 2011 22:22

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by gothon »

Hi dodicat, I tried your code. It seems to render the cube only on the first frame. Later frames only show the red background rendered by 'glClear(GL_COLOR_BUFFER_BIT)'. This suggests to me that the render state somehow changed after the first frame before subsequent frames where rendered. Adding a call to your 'glsetup' function atop the render loop seems to confirm this.

(p.s. The GL_ONE,GL_ONE blending function is a nice touch, it makes the ball and cube blend together)

After further investigation I saw that the code posted by angros47 seems to push the projection matrix stack, but it pops the model-view matrix stack.
viewtopic.php?f=17&t=25902&start=15#p236050

I have found it is also possible to get your code working by guarding the flip call with:

Code: Select all

    glMatrixMode GL_MODELVIEW
    glPushMatrix
    Flip
    glMatrixMode GL_PROJECTION
    glPopMatrix
    glMatrixMode GL_MODELVIEW
This is probably a bug in the new feature!
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by dodicat »

Thanks gothon.
It is now identical to texturing without using angros47's library, including the transparency as the ball crosses over the cube (which is not really wanted)
set16
Posts: 4
Joined: Mar 22, 2019 13:04

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by set16 »

replace

Code: Select all

glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA)
Add

Code: Select all

do
...
Color(,RGBA(0,0,0,0))
...
loop
the circle will not be transparent
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by coderJeff »

gothon wrote:...After further investigation I saw that the code posted by angros47 seems to push the projection matrix stack, but it pops the model-view matrix stack.
...
This is probably a bug in the new feature!
@gothon, thanks for your pull request. Fixed in fbc 1.07.0.
set16
Posts: 4
Joined: Mar 22, 2019 13:04

Re: [Patch] Rendering of FreeBasic graphic on OpenGL

Post by set16 »

Does not work in VBO when you connect the light in the Shader

Code: Select all

#version 140

uniform sampler2D textures;

in  vec2  ex_texcoord;
in vec4 vFinalColor;

out vec4 out_colour;

void main(void)
{
	
	out_colour = texture(textures, ex_texcoord);//*vFinalColor; //<<<<<<<<<<<<<<< here
}

Code: Select all

#version 140
uniform mat4 projection;
uniform mat4 modelview;
in  vec3 position;
in  vec3 normal;
in  vec2 texcoord;
out vec2 ex_texcoord;
out vec4 vFinalColor;
const vec3 vLightDirection = vec3(-1.0, -1.0, -1.0);
void main()
{

		mat3 nv = mat3(modelview);
		vec3 N = normalize( nv * normal);
       		vec3 L = normalize(vLightDirection);
        	float lambertComponent = max(dot(N, -L), 0.2);
       		vec3 diffuseLight = vec3(lambertComponent,lambertComponent,lambertComponent);
        	vFinalColor = vec4(diffuseLight, 1.0);
		gl_Position =  projection * modelview *vec4(position, 1.0); 
		ex_texcoord = texcoord;
}
Post Reply