Dark Bit Factory & Gravity

PROGRAMMING => Purebasic => Topic started by: inc. on October 19, 2016

Title: Question about OGL / GLSL Shader use
Post by: inc. on October 19, 2016
Hi at all,

today i have a question about the usage in PB with OGL/ GLSL Shaders.
I managed my code and the compilation show me the correct shaders and so on.

My big question is:
does someone know, how it is possible to add GFX and or 3d (*.3ds Objects) on this PB_OGL_ GADGED - Screen?
I wanna add my text scroller or a typer and group logo ect.

In a DX9 screen plus HLSL shader all is fine and works good.

thanks for useful help.



Title: Re: Question about OGL / GLSL Shader use
Post by: Rbz on October 23, 2016
Hi inc.,

I know almost nothing about Purebasic inner working, but I believe what you are trying to do is to having a quad displaying a shader program/effect and on top of that displaying a text scroller or image, right?

If that's correct, on your opengl screen, draw a quad, with same size of your screen width/height, and apply a shader program do it,  disable opengl depth_test and then draw another quad or quad strip (size w/h of your text font) and apply your texture scroller, a 3D object can be drawn this same way.

I hope that help, and if you like, you can post a example code and I'll take a look at it.
Title: Re: Question about OGL / GLSL Shader use
Post by: inc. on October 23, 2016
Thanks for the reply.  I do a small code and attach it next week.
Will try your Suggestion.
Title: Re: Question about OGL / GLSL Shader use
Post by: Rbz on October 27, 2016
Hi inc.,

I've tried the example code you sent to me, but Purebasic Demo version refused to run it  :-\, I think it can only run sources below 800 lines of code or something.

Anyway, looking at the source, I can see that you use a quad that covers your opengl screen and start the shader program but without properly setting up opengl projection, try something like this:

Code: [Select]
Procedure Render();Setup 2D projection:
Code: [Select]
glViewport(0, 0, screen_width, screen_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)screen_width, (GLdouble)screen_height,0.0);
glDisable(GL_DEPTH_TEST);

Start Shader code, I believe you do this in Purebasic:
Code: [Select]
  System\Shader_Program = Shader_Compile_Link_Use(System\Shader_Vertex_Text,System\Shader_Fragment_Text)
  If System\Shader_Program = 0
    MessageRequester("Unsupported Device?","No Shader Support Available",#PB_MessageRequester_Ok)
    End
  EndIf

Draw a quad that covers your entire screen:
Code: [Select]
glPushMatrix();
glTranslatef(0.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f);
glVertex2d( 0, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex2d( screen_width, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex2d( screen_width, screen_height);
glTexCoord2f(0.0f, 0.0f); glVertex2d( 0, screen_height);
glEnd();
glPopMatrix();

Stop Shader program:
Code: [Select]
      glUseProgram(0);
Now draw your quad with logo texture:
Code: [Select]
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Logo_Texture);
glTranslatef(0.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f);
glVertex2d( 0, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex2d( logo_width, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex2d( logo_width, logo_height);
glTexCoord2f(0.0f, 0.0f);
glVertex2d( 0, logo_height);
glEnd();
glPopMatrix();

Code: [Select]
  SetGadgetAttribute(#Gad_OpenGL,#PB_OpenGL_FlipBuffers,1)
 
EndProcedure


I hope that help you :)

Title: Re: Question about OGL / GLSL Shader use
Post by: inc. on October 27, 2016
Great.  I'll give a try tomorrow. 
Yes, PB Demo only allow a few lines.
But thanks so far. PadMan pushed me in the right Direction too.
Feedback very soon.