OpenGL 3.3 Base (windows)

Advanced game related topics
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: OpenGL 3.3 Base (windows)

Post by Danilo »

Thanks xorc1zt! Very nice, but did not work out of the box:
- first nothing happend when starting the examples
- enabled debugger, it told me opengl subsystem is required (can you set opengl subsys in you examples by default?)
- added subsystem opengl in compileroptions for all 3 examples
- always same crash:

Code: Select all

[ERROR] Invalid memory access. (read error at address 0)
- I replaced the 2 macros with:

Code: Select all

Procedure.s glGetStringi(name,index)
    Define *stringpointer
    If glGetStringi_
        *stringpointer = glGetStringi_(name,index)
        If *stringpointer
            ProcedureReturn PeekS( *stringpointer )
        EndIf
    EndIf
   
  
    ProcedureReturn "#NULL"
EndProcedure

Procedure.s glGetString(name)
    Define *stringpointer
   
    If glGetString_
        *stringpointer = glGetString_(name)
       
        If *stringpointer
            ProcedureReturn PeekS( *stringpointer )
        EndIf
    EndIf
   
    ProcedureReturn "#NULL"
EndProcedure
- now the error comes for: id = glCreateShader( type )

Code: Select all

[ERROR] Invalid memory access. (read error at address 0)


Now i disabled unicode mode and everything works fine!

In Unicode mode many functions are Null, OpenGL Info is:

Code: Select all

--- OpenGL Infos:
OpenGL Vendor: 		呁⁉敔档潮潬楧獥䤠据.
OpenGL Renderer: 	䵁⁄慒敤湯䠠⁄㤶〰匠牥敩s 6900 Series
OpenGL Version: 	⸴⸲ㄱ㤳‹潃灭瑡扩汩瑩⁹牐景汩⁥潃瑮硥t
OpenGL Shader: 		⸴〲㄀㤳9
With disabled unicode mode everything is fine:

Code: Select all

--- OpenGL Infos:
OpenGL Vendor: 		ATI Technologies Inc.
OpenGL Renderer: 	AMD Radeon HD 6900 Series
OpenGL Version: 	4.2.11399 Compatibility Profile Context
OpenGL Shader: 		4.20
Does GetFunction() in setGLCORE not work with unicode strings?

You may want the full log files: pbgl_log.zip

Thank you!
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: OpenGL 3.3 Base (windows)

Post by xorc1zt »

thanks for your feedback, everything should be fixed now.

The problem was that opengl doesn't handle unicode and i did all the prototype quickly with a script and didn't tough about unicode.

to fix this i did
1. replace prototype string argument with .p-ascii
2. import wgl functions myself, the purebasic ones doesn't convert string arguments to ascii.
4. add #PB_ASCII to PeekS
3. convert the shader source code to ascii before call glshadersource()

link http://demo.ovh.com/en/c08cf531f2812b8a ... 619cc96e9/

edit: about opengl subsystem, i don't know how to set it automatically and you don't need it if you use windows api like the orthogonal example.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: OpenGL 3.3 Base (windows)

Post by Danilo »

xorc1zt wrote:thanks for your feedback, everything should be fixed now.
Thanks xorc1zt, works better now.

There is still a small mistake that makes EXAMPLE_ORTHOGONAL.pb crash w/o debugger.
After enabling the Debugger I got a crash at a point i could not see an error. I tried again
and the error was different and on an other line in the source.
So i enabled the Purifier in compiler options and... voila:

Code: Select all

[ERROR] glbase.pb (Line: 1360)
[ERROR] Overflow in a dynamically allocated memory block.
It is in the procedure pbglLoadShader():

Code: Select all

        CompilerIf #PB_Compiler_Unicode
            *pbuff = AllocateMemory( Len(sourcestringbuffer)+SizeOf(Character) ) ; should be Len() + SizeOf(Character)
            PokeS( *pbuff, sourcestringbuffer, -1, #PB_Ascii )
and 5 lines below:

Code: Select all

        CompilerIf #PB_Compiler_Unicode
            *pbuff = AllocateMemory( Len(source)+SizeOf(Character) ) ; should be Len() + SizeOf(Character)
            PokeS( *pbuff, source, -1, #PB_Ascii )
PokeS() adds a terminating 0 after the string content, and for Unicode it is two 0's.

After this small changes everything works fine here so far. Maybe adding some
checks after all AllocateMemory would be good, in case it fails and returns 0.
xorc1zt wrote:The problem was that opengl doesn't handle unicode and i did all the prototype quickly with a script and didn't tough about unicode.
I also forgot about Unicode very often and wrote things like '*pointer + 1'.
To force myself to write better code, i enabled Unicode in the default compiler settings, so it is
always enabled here for new sources. This way I can't forget it and got used to it after a while. :)
xorc1zt wrote:edit: about opengl subsystem, i don't know how to set it automatically and you don't need it if you use windows api like the orthogonal example.
Just set it in compiler options for the 3 examples:

Code: Select all

Library Subsystem: [ opengl                ]
and save the source again after the change.

If you open the sources with another text editor, you see the hidden options
at the end of .pb files. For example:

Code: Select all

; EnableUnicode
; EnableXP
; CPU = 5
; SubSystem = opengl
; EnablePurifier
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: OpenGL 3.3 Base (windows)

Post by xorc1zt »

thanks

i tried on x64 only and there was no errors
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: OpenGL 3.3 Base (windows)

Post by HeX0R »

You might also add this to the head of your source:

Code: Select all

CompilerIf Subsystem("OpenGL") = 0
	CompilerError "You have to enable OpenGL Subsystem to run this code"
CompilerEndIf
(not anyone uses the hidden parameters in the source)
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: OpenGL 3.3 Base (windows)

Post by xorc1zt »

already done at _pbglInitGLBase(), i don't use the purebasic ide but Sublime Text

Code: Select all

    If _pbgl_setting\pbgl_context_method = #PBGL_PUREBASIC  
        CompilerIf Subsystem( "OpenGL" ) = #False
            Debug "You must use OpenGL as subsystem !!!"
            End
        CompilerEndIf
        
        If Not InitSprite()
            Debug "initsprite fail"
            End
        EndIf
    EndIf
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: OpenGL 3.3 Base (windows)

Post by mpz »

Hi xorc1zt,

i can't download your files. I think the downloadlink is down. Can you actualize the download link please?


Thanks Michael
Working on - MP3D Library - PB 5.73 version ready for download
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: OpenGL 3.3 Base (windows)

Post by xorc1zt »

sorry,

here the files : http://www.mediafire.com/?ms936a01nea7p6c

added pbglGetTimeDelta() which return fixed delta time
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: OpenGL 3.3 Base (windows)

Post by mpz »

Hello xorc1zt ,

thx for your help. I write a Shader Tutorial for hlsl (DX9) Shader in the german forum now and think about a program to convert hlsl shader and glsl shader. Can you use these kind of glsl shader (see code plz) with you opengl addon too ? I think you need two files (vertex and frag shader ) but i dont understand the difference between your Shader and the glsl shader...

Greetings
Michael


Here the code:

Code: Select all

// Chessboard Zoomer ;)

#ifdef GL_ES
precision mediump float;
#endif

uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;

void main( void ) {

	vec2 p = ( gl_FragCoord.xy / resolution.xy ); 

	float color = 0.0;
	
	vec2 t = p* 1.5/sin(time/8.); 
	if( mod(t.x, 1.9) > 1. == mod(t.y, 1.9) > 1.0 )
		color = 1.; 
	else 
		color = 0.; 
	
	gl_FragColor = vec4( color, 1.0, 1.0, 1.0 );

}
Working on - MP3D Library - PB 5.73 version ready for download
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: OpenGL 3.3 Base (windows)

Post by xorc1zt »

they are no difference because i simply use the opengl shader. my function is a helper which call the opengl functions to load, compile the shaders then link the shaders to the program.

actually opengl allow 3 type of shader per program (see http://en.wikipedia.org/wiki/Shader#Types_of_shaders)

GL_VERTEX_SHADER
GL_GEOMETRY_SHADER ( optional )
GL_FRAGMENT_SHADER ( also know as pixel shader )

my function is just doing this

1. create and load a vertex shader from file or from memory buffer
create and load a fragment shader from file or from memory buffer
2. create a program
3. link both shaders to the progam
4. delete both shaders
5. return the program id.

the shader you gave here is a framgent shader.

edit:

create a shader : glCreateShader
load source code to the shader : glShaderSource
compile the shader : glCompileShader

create a program : glCreateProgram
attach shader to the program : glAttachShader
link a program : glLinkProgram

delete a shader : glDeleteShader
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: OpenGL 3.3 Base (windows)

Post by mpz »

Hi,

thanks for the news. I will test it with your programm and hope i will find a working solution...

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: OpenGL 3.3 Base (windows)

Post by eesau »

By the way, the include file won't work in PB 5.1 because of native types appended to pointers. Easy to fix though...

xorc1zt, would you happen to have a working example of using vbo's with 3.3 core profile? (glGenBuffers, glBindBuffer, glDrawElements and so on). For some reason I can't get them to work, there are no errors (glGetError returns 0 for every line), but nothing is rendering.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: OpenGL 3.3 Base (windows)

Post by eesau »

Hah, I made it work after spending two days trying. Turns out everything was ok, I just had a tiny mispelt variable in my shader. :oops:

OpenGL 3.3 is amazingly clean and easy.
Zach
Addict
Addict
Posts: 1654
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: OpenGL 3.3 Base (windows)

Post by Zach »

Anyone have a download link for the latest, up to date and working version of this library?

I'm interested in trying it but all the download links seem dead.. I found what I assume is a much older version via his forum signature link, but it has tons of native types assigned to pointers, etc and I already broke it trying to delete those en masse :oops:
Image
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: OpenGL 3.3 Base (windows)

Post by luis »

Anyone who got a copy of this lib, any version, even if not working anymore - I don't care, could make it available for a while ?

I thought I had downloaded it at the time but I cannot find it anymore.


EDIT: some kind soul sent it through PM, so I'm good now :wink:

Thanks.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply