Page 1 of 2

OpenGL examples with OpenGLGadget (modern and old demos)

Posted: Sun Jun 22, 2014 9:34 pm
by applePi
the recent OpenGLGadget are great as an environment to display OpenGL code, it is simplifying things too much, i have tried it to display the opengl 4 code in C++ found here:
http://antongerdelan.net/opengl/hellotriangle.html
so your card should support OpenGL 4.x and have its drivers installed
i have considered C++ as a pseudo code
what we need is the
"GLEXT.PBI" from luis here: http://purebasic.fr/english/viewtopic.p ... 87#p348385
"MoreFunctions.pbi" attached below which contains functions some from xorc1zt include file in the OpenGL 3.3 Base (windows) and what is related to opengl 4 i have used the definitions in http://www.rastertek.com/gl40tut03.html
native "OpenGL.pbi" refered to remotely
it is tutorial number one in that page from many goodies available
http://antongerdelan.net/opengl/index.html

MoreFunctions.pbi _ also include the "GLEXT.PBI" mentioned above

Code: Select all

;from luis reply http://purebasic.fr/english/viewtopic.php?f=13&t=45687&start=15#p446875
CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86)
Import "Opengl32.lib" 
 wglGetProcAddress_(s.p-ascii) As "_wglGetProcAddress@4"
EndImport
 CompilerElse   
Import "Opengl32.lib" 
 wglGetProcAddress_(s.p-ascii) As "wglGetProcAddress"
EndImport
CompilerEndIf

Prototype PFNGLGENBUFFERSPROC ( n.i, *buffers)
Global glGenBuffers.PFNGLGENBUFFERSPROC
glGenBuffers = wglGetProcAddress_( "glGenBuffers" )
Prototype PFNGLBINDBUFFERPROC ( target.l, buffer.i)
Global glBindBuffer.PFNGLBINDBUFFERPROC
glBindBuffer = wglGetProcAddress_( "glBindBuffer" )
Prototype PFNGLBUFFERDATAPROC ( target.l, size.i, *Data_, usage.l)
Global glBufferData.PFNGLBUFFERDATAPROC
glBufferData = wglGetProcAddress_( "glBufferData" )

Prototype PFNGLGENVERTEXARRAYSPROC (n.i, *arrays)
Global glGenVertexArrays.PFNGLGENVERTEXARRAYSPROC
glGenVertexArrays = wglGetProcAddress_( "glGenVertexArrays" )

Prototype PFNGLBINDVERTEXARRAYPROC(n.i)
Global glBindVertexArray.PFNGLBINDVERTEXARRAYPROC
glBindVertexArray = wglGetProcAddress_( "glBindVertexArray" )

Prototype PFNGLENABLEVERTEXATTRIBARRAYPROC ( index.i )
Global glEnableVertexAttribArray.PFNGLENABLEVERTEXATTRIBARRAYPROC
glEnableVertexAttribArray = wglGetProcAddress_( "glEnableVertexAttribArray" )

Prototype PFNGLVERTEXATTRIBPOINTERPROC ( index.i, size.i, type.l, normalized.b, stride.i, *pointer )
Global glVertexAttribPointer.PFNGLVERTEXATTRIBPOINTERPROC
glVertexAttribPointer = wglGetProcAddress_( "glVertexAttribPointer" )

Prototype.i PFNGLCREATESHADERPROC ( type.l )
Global glCreateShader.PFNGLCREATESHADERPROC
glCreateShader = wglGetProcAddress_( "glCreateShader" )


Prototype PFNGLSHADERSOURCEPROC ( shader.i, count.i, *stringBuffer, *length )
Global glShaderSource.PFNGLSHADERSOURCEPROC
glShaderSource = wglGetProcAddress_( "glShaderSource" )


Prototype PFNGLCOMPILESHADERPROC ( shader.i )
Global glCompileShader.PFNGLCOMPILESHADERPROC
glCompileShader = wglGetProcAddress_( "glCompileShader" )


Prototype PFNGLATTACHSHADERPROC ( program.i, shader.i )
Global glAttachShader.PFNGLATTACHSHADERPROC
glAttachShader = wglGetProcAddress_( "glAttachShader" )


Prototype PFNGLLINKPROGRAMPROC ( program.i )
Global glLinkProgram.PFNGLLINKPROGRAMPROC
glLinkProgram = wglGetProcAddress_( "glLinkProgram" )

Prototype.i PFNGLCREATEPROGRAMPROC ( )
Global glCreateProgram.PFNGLCREATEPROGRAMPROC
glCreateProgram = wglGetProcAddress_( "glCreateProgram" )

Prototype PFNGLUSEPROGRAMPROC ( program.i )
Global glUseProgram.PFNGLUSEPROGRAMPROC
glUseProgram = wglGetProcAddress_( "glUseProgram" )

Prototype PFNGLDRAWARRAYSPROC ( mode.l, first.i, count.i )
Global glDrawArrays.PFNGLDRAWARRAYSPROC
glDrawArrays = wglGetProcAddress_( "glDrawArrays" )


Code: Select all

OpenWindow(0, 10, 10, 640, 480, "OpenGL demo")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 20, 10, WindowWidth(0)-40 , WindowHeight(0)-20)

IncludeFile "MoreFunctions.pbi"
IncludeFile "GLEXT.pbi"

Global Dim points.f(8) 
points(0)= 0.0 : points(1)= 0.5 : points(2)=0.0 
points(3)= 0.5 : points(4)= -0.5 : points(5)= 0.0
points(6)= -0.5 :  points(7)= -0.5 : points(8)= 0.0


Define vertex_shader.s
Define fragment_shader.s
Define *vbuff

;vertex shader source code
    vertex_shader = "#version 400"+#CRLF$
    vertex_shader + "in vec3 vp;"+#CRLF$
    vertex_shader + "void main() { "+#CRLF$
    vertex_shader + "gl_Position = vec4 (vp, 1.0);"+#CRLF$
    vertex_shader + "}"
           
    ;fragment shader source code
    fragment_shader = "#version 400"+#CRLF$
    fragment_shader + "out vec4 frag_colour;"+#CRLF$
    fragment_shader + "void main() {"+#CRLF$
    fragment_shader + "frag_colour = vec4 (0.5, 0.0, 0.5, 1.0);"+#CRLF$
    fragment_shader + "}"
        
    *vbuff = @vertex_shader
    *fbuff = @fragment_shader
    
glEnable_(#GL_DEPTH_TEST); // enable depth-testing
glDepthFunc_(#GL_LESS); // depth-testing interprets a smaller value as "closer"

Global vbo.i,vao.i

;=================================================================================

glGenBuffers( 1, @vbo )
glBindBuffer(#GL_ARRAY_BUFFER, vbo )
glBufferData(#GL_ARRAY_BUFFER,9 * SizeOf(float), @points(0), #GL_STATIC_DRAW)

glGenVertexArrays(1, @vao);
glBindVertexArray (vao)   ;
glEnableVertexAttribArray (0);
glBindBuffer (#GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer (0, 3, #GL_FLOAT, #GL_FALSE, 0, #Null);

Global vs = glCreateShader(#GL_VERTEX_SHADER);
glShaderSource(vs, 1, @*vbuff, #Null) ;
glCompileShader(vs);
Global fs = glCreateShader(#GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, @*fbuff, #Null);
glCompileShader(fs)                          ;

Global shader_programme = glCreateProgram();
glAttachShader(shader_programme, fs);
glAttachShader(shader_programme, vs);
glLinkProgram(shader_programme)     ;

Repeat
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT);
  glUseProgram(shader_programme)  
  glBindVertexArray(vao);
  ;draw points 0-3 from the currently bound VAO With current in-use shader
  glDrawArrays(#GL_TRIANGLES, 0, 3);
    
  ;SwapBuffers_(hdc)
  ;Delay(16)
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Until WindowEvent() = #PB_Event_CloseWindow



example 2:
is a rotating rectangle, and easier than the first example.
so we can use purebasic to learn opengl 4+ much more easily than the complexities in C/C++

Code: Select all

Structure TVertex
  x.f
  y.f
  z.f
EndStructure


OpenWindow(0, 10, 10, 640, 480, "OpenGL demo")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 20, 10, WindowWidth(0)-40 , WindowHeight(0)-20)

IncludeFile "MoreFunctions.pbi"
IncludeFile "GLEXT.pbi"

Define vertex_shader.s
Define fragment_shader.s


glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glMatrixMode_(#GL_MODELVIEW)
glTranslatef_(0, 0, -5)
glShadeModel_(#GL_SMOOTH) 
glEnable_(#GL_DEPTH_TEST)
;glEnable_(#GL_CULL_FACE) 
glColor3f_(1.0, 0.3, 0.0)
glViewport_(0, 0, 800, 600)

Global vbo.i,vao.i
Dim Vertex.TVertex(3)
Vertex(0)\x = 1
Vertex(0)\y = -1
Vertex(0)\z = 0

Vertex(1)\x = -1
Vertex(1)\y = -1
Vertex(1)\z = 0

Vertex(2)\x = 1
Vertex(2)\y = 1
Vertex(2)\z = 0

Vertex(3)\x = -1
Vertex(3)\y = 1
Vertex(3)\z = 0
;=================================================================================
;=================================================================================
Dim index.l(5)
index(0) = 1 
index(1) = 0
index(2) = 2
index(3) = 3
index(4) = 1
index(5) = 2

;indexsize = 6 ;#GL_UNSIGNED_BYTE
indexsize = 6*2 ;#GL_UNSIGNED_SHORT
indexsize = 6*4 ;#GL_UNSIGNED_INT

glGenBuffers( 1, @vbo ) ; Vertex Buffer Object
glBindBuffer(#GL_ARRAY_BUFFER, vbo )
glBufferData(#GL_ARRAY_BUFFER,SizeOf(TVertex)*4,@Vertex(0), #GL_STATIC_DRAW)
glBindBuffer(#GL_ARRAY_BUFFER,0);
glGenBuffers( 1, @vao );  Vertex Attribute Object
glBindBuffer(#GL_ELEMENT_ARRAY_BUFFER, vao);
glBufferData(#GL_ELEMENT_ARRAY_BUFFER, indexsize,@index(0),#GL_STATIC_DRAW);
glBindBuffer(#GL_ELEMENT_ARRAY_BUFFER, 0);
rot.f = 1

Repeat
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  glClearColor_(0.2, 0.9, 0.2, 1)
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glEnableClientState_(#GL_VERTEX_ARRAY )
  glRotatef_(rot, 0, 1, 0);
  glBindBuffer(#GL_ARRAY_BUFFER, vbo)
  glVertexPointer_(3, #GL_FLOAT,0,0)
    
  glBindBuffer(#GL_ELEMENT_ARRAY_BUFFER, vao)
  glDrawElements_(#GL_TRIANGLES,indexsize,#GL_UNSIGNED_INT,0)
  glBindBuffer(#GL_ELEMENT_ARRAY_BUFFER, 0);
  glBindBuffer(#GL_ARRAY_BUFFER,0);
  glDisableClientState_(#GL_VERTEX_ARRAY);

  ;SwapBuffers_(hdc)
  ;Delay(16)
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Until WindowEvent() = #PB_Event_CloseWindow

Re: Modern OpenGL examples with OpenGLGadget

Posted: Sun Jun 22, 2014 10:58 pm
by luis
Thanks.

I know this is intended as a simple demo for the forum and it's ok, but some notes for when developing a real program just to imprint the right way from the start in people wanting to play with this:

1) If you are targeting a minimum opengl version, test for it and quit with a message if it's not there

2) When using a COMPATIBLE PROFILE (like in this case) always test for the presence of the appropriate extension before using a command that it's core just in a version above the opengl you are targeting.

3) When using a shader remember opengl expect ascii data, so your shaders in the first program will not work in unicode mode, you have to create an ascii buffer to pass to the source to opengl

4) always assume everything will fail, because likely it will do so on some hw/sw. This means : when compiling a shader, always test if the compilation is successful, if not log the error somewhere AND when importing a gl command always check you didn't get a null pointer and log this somewhere if you did.

5) when you are learning, always check for errors often: using a simple glGetError() is enough for a start. A check every frame is enough to get errors quickly before you go too much forward to be able trace them easily.

Again, not nitpicking here for this specific code, just wanted to mention it because these are things not mentioned a lot before and can save headaches.

I promise to not repeat this again next time :)

Re: Modern OpenGL examples with OpenGLGadget

Posted: Mon Jun 23, 2014 4:37 am
by applePi
luis said:
I promise to not repeat this again next time
no i and the others needs the info and more ,so we can use the new opengl the correct way.

but how to test for the minimum opengl version suppose for example 1 i want to check for version 4.0.
you said before http://purebasic.fr/english/viewtopic.p ... 7&start=15
"
The correct way to do so is to create a RC, load the list of extensions, check if the string GL_ARB_vertex_buffer_object is present, and if true import the functions and define the constant listed in the specifications linked above
."
how to check the presence of the string GL_ARB_vertex_buffer_object

i want to add this reference for more info about modern opengl
http://www.arcsynthesis.org/gltut/index.html Learning Modern 3D Graphics Programming
http://antongerdelan.net/opengl/index.html
any other references will be great.

Re: Modern OpenGL examples with OpenGLGadget

Posted: Mon Jun 23, 2014 11:18 am
by luis
applePi wrote: but how to test for the minimum opengl version suppose for example 1 i want to check for version 4.0.
Simply use #GL_VERSION

These should give you a general idea

Code: Select all


Procedure sgl_GetGLVersion (*Major.Integer, *Minor.Integer, *Release.Integer)
; [DESC]
; Get the OpenGL version number.
;
; [OUTPUT]
; *Major : The major version number (for example 4).
; *Minor : The minor version number (for example 1).
; *Release : The release number (for example 0).
;
; [RETURN]
; NONE

 ASS(sgl_GetRC())
 
 Protected GL_Version$ = StringField(sgl_GetGLVersionString(), 1, " ")
 Protected GL_Major = Val(StringField(GL_Version$, 1, "."))
 Protected GL_Minor = Val(StringField(GL_Version$, 2, "."))
 Protected GL_Release = Val(StringField(GL_Version$, 3, "."))
 
 *Major\i = GL_Major
 *Minor\i = GL_Minor
 *Release\i = GL_Release
EndProcedure

Procedure.s sgl_GetGLVersionString()
; [DESC]
; Get the OpenGL version number as a string.
;
; [RETURN]
; A string representing the OpenGL version number (for example: "4.1.0").

 ASS(sgl_GetRC()) 
 ProcedureReturn (PeekS(glGetString_(#GL_VERSION),-1,#PB_Ascii))
EndProcedure

Procedure.i sgl_GetGLVersionToken()
; [DESC]
; Get the OpenGL version number as a token (a single integer).
;
; [RETURN]
; A integer number, for example: 410 for OpenGL 4.1, 120 for OpenGL 1.2, etc.
; Only the major and minor release number are reported back by this command.
; The release number is NEVER considered, so you could use this to make flow control decision in
; your program but not to report the complete OpenGL driver version to the user.

 ASS(sgl_GetRC())
 
 Protected GL_Version$ = StringField(sgl_GetGLVersionString(), 1, " ")
 Protected GL_Major = Val(StringField(GL_Version$, 1, "."))
 Protected GL_Minor = Val(StringField(GL_Version$, 2, "."))
 
 ProcedureReturn GL_Major * 100 + GL_Minor * 10
EndProcedure

for use extensions see this -> http://www.opengl.org/archives/resource ... xtensions/

The way to check for extensions is changed a little in core profiles, but using PB glgadget you are using the compatible profile so the above is the most compatible way to do it.

Basically you load all the strings extension, and check for the one you are looking for, if it's present the extension is supported and you can bind the function addresses to your prototypes.

This is some code to load the list of extensions under windows

Code: Select all

Procedure.i os_EnumOpenGLExtensions()  
 Protected i, cnt
 Protected Buffer$, ExtName$
 Protected ExtCount, ExtSource
 Protected *fpGetExtensionsString, *ptr
 Protected NewMap UniqueExt()
 
 cnt = 0
 
 For ExtSource = 1 To 3 ; three different ways 
    Buffer$ = ""
    
    Select ExtSource
        Case 1 ; usual way
            *ptr = glGetString_(#GL_EXTENSIONS)
            If *ptr
                Buffer$ = PeekS(*ptr,-1,#PB_Ascii)
            EndIf
        Case 2 ; some of them are only available through a "wiggle" 
            *fpGetExtensionsString = os_GetProcAddress("wglGetExtensionsStringARB")            
            If *fpGetExtensionsString
                Buffer$ = PeekS(CallFunctionFast(*fpGetExtensionsString, wglGetCurrentDC_()),-1,#PB_Ascii)
            EndIf
        Case 3 ; possible alias of the "wiggle" above, just to be sure
            *fpGetExtensionsString = os_GetProcAddress("wglGetExtensionsStringEXT")            
            If *fpGetExtensionsString
                Buffer$ = PeekS(CallFunctionFast(*fpGetExtensionsString),-1,#PB_Ascii)
            EndIf                                
    EndSelect 
    
    If Len(Buffer$) ; split the buffer contents
        ExtCount = CountString(Buffer$, " ")
        For i = 1 To ExtCount
            ExtName$ = StringField(Buffer$, i, " ")                
            UniqueExt(ExtName$) = 1 
        Next
    EndIf 
 Next
 
 cnt = MapSize(UniqueExt()) ; now we have [cnt] unique extensions
           
 Dim SGL\ExtensionsStrings$(cnt - 1)
 ASS(ArraySize(SGL\ExtensionsStrings$()) <> -1)
 
 cnt = 0
 
 ResetMap(UniqueExt())
 
 ; let's copy them
 While NextMapElement(UniqueExt())    
    SGL\ExtensionsStrings$(cnt) = MapKey(UniqueExt())
    cnt + 1
 Wend
 
 ; and sort them
 SortArray(SGL\ExtensionsStrings$(), #PB_Sort_Ascending)
 
 ProcedureReturn cnt
EndProcedure
Confront it with what suggested in the link above and you will find it similar.

Then I use a dichotomic search to look into the array, but obviously you can keep them in a map if you prefer, or whatever.

Some extensions does not introduce new constants or new functions, they just remove some limitation from previous commands, so if they are presents you know those restrictions has been lifted.

Some extensions just add new "tokens" (constants) to extend some previous command to work with different, new parameter values.

Some extensions add new tokens and new functions.

Also what you are using with PB remember is a compatibility profile, so you can mix deprecated stuff with modern stuff. You can simply use only modern stuff if you like to write code easily portable to a core profile in the future.

Re: Modern OpenGL examples with OpenGLGadget

Posted: Mon Jun 23, 2014 12:51 pm
by applePi
Thanks luis for the generous reply and info, this makes almost enough info for who want to write programs for the modern opengl in purebasic and want it to be used by the others. this info are necessary reference.
in my investigations i will post sometimes the short demo version of the examples i may study.
i hesitate to ask the last question:

Code: Select all

;vertex shader source code
    vertex_shader = "#version 400"+#CRLF$
    vertex_shader + "in vec3 vp;"+#CRLF$
    vertex_shader + "void main() { "+#CRLF$
    vertex_shader + "gl_Position = vec4 (vp, 1.0);"+#CRLF$
    vertex_shader + "}"

*vbuff = @vertex_shader
....
Global vs = glCreateShader(#GL_VERTEX_SHADER);
glShaderSource(vs, 1, @*vbuff, #Null) ;
glCompileShader(vs);

you said "3) When using a shader remember opengl expect ascii data, so your shaders in the first program will not work in unicode mode, you have to create an ascii buffer to pass to the source to opengl"
how to interpret this to the above code parts . that is the last question. thanks

Re: Modern OpenGL examples with OpenGLGadget

Posted: Mon Jun 23, 2014 2:34 pm
by luis
applePi wrote:i hesitate to ask the last question
Ask away :)
applePi wrote:you said "3) When using a shader remember opengl expect ascii data, so your shaders in the first program will not work in unicode mode, you have to create an ascii buffer to pass to the source to opengl"
how to interpret this to the above code parts . that is the last question. thanks
You need to convert the unicode string with the shader source to an ascii string before invoking any opengl command involving strings. Unfortunately this time it's not a single string, so the pseudotype p-ascii can't be used AFAIK.
You are expected to pass a pointer to an array of pointers, not to a single string and so you have to convert the buffer by yourself.

This is (part) of your fist example with a way to do it (you can see something similar in xorc1zt's demo too):

Code: Select all

Procedure.i GetShaderSourceBuf (*shader) ;--> *NEW*
 Protected *p, l, t$
 
 CompilerIf #PB_Compiler_Unicode
    t$ = PeekS(*shader, -1) : l = Len(t$)
    *p = AllocateMemory(l + SizeOf(Character)) 
    If *p
        PokeS(*p, t$, l, #PB_Ascii)
    EndIf
CompilerElse   
    *p = *shader
CompilerEndIf

 ProcedureReturn *p
EndProcedure

Procedure FreeShaderSourceBuf (*p) ;--> *NEW*
 CompilerIf #PB_Compiler_Unicode    
    If *p
        FreeMemory(*p)
    EndIf
 CompilerEndIf
EndProcedure


Global Dim points.f(8)
points(0)= 0.0 : points(1)= 0.5 : points(2)=0.0
points(3)= 0.5 : points(4)= -0.5 : points(5)= 0.0
points(6)= -0.5 :  points(7)= -0.5 : points(8)= 0.0


Define vertex_shader.s
Define fragment_shader.s
Define *vbuff

    ;vertex shader source code
    vertex_shader = "#version 400"+#CRLF$
    vertex_shader + "in vec3 vp;"+#CRLF$
    vertex_shader + "void main() { "+#CRLF$
    vertex_shader + "gl_Position = vec4 (vp, 1.0);"+#CRLF$
    vertex_shader + "}"
           
    ;fragment shader source code
    fragment_shader = "#version 400"+#CRLF$
    fragment_shader + "out vec4 frag_colour;"+#CRLF$
    fragment_shader + "void main() {"+#CRLF$
    fragment_shader + "frag_colour = vec4 (0.5, 0.0, 0.5, 1.0);"+#CRLF$
    fragment_shader + "}"

    *vbuff = GetShaderSourceBuf(@vertex_shader)   ;--> *NEW*
    *fbuff = GetShaderSourceBuf(@fragment_shader) ;--> *NEW*
   
glEnable_(#GL_DEPTH_TEST); // enable depth-testing
glDepthFunc_(#GL_LESS); // depth-testing interprets a smaller value as "closer"

Global vbo.i,vao.i

;=================================================================================

glGenBuffers( 1, @vbo )
glBindBuffer(#GL_ARRAY_BUFFER, vbo )
glBufferData(#GL_ARRAY_BUFFER,9 * SizeOf(float), @points(0), #GL_STATIC_DRAW)

glGenVertexArrays(1, @vao);
glBindVertexArray (vao)   ;
glEnableVertexAttribArray (0);
glBindBuffer (#GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer (0, 3, #GL_FLOAT, #GL_FALSE, 0, #Null);

Global vs = glCreateShader(#GL_VERTEX_SHADER);
glShaderSource(vs, 1, @*vbuff, #Null) ;
glCompileShader(vs);
Global fs = glCreateShader(#GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, @*fbuff, #Null);
glCompileShader(fs)                          ;

Global shader_programme = glCreateProgram();
glAttachShader(shader_programme, fs);
glAttachShader(shader_programme, vs);
glLinkProgram(shader_programme)     ;

FreeShaderSourceBuf(*vbuff) ;--> *NEW*
FreeShaderSourceBuf(*fbuff) ;--> *NEW*

Repeat
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT);
  glUseProgram(shader_programme) 
  glBindVertexArray(vao);
  ;draw points 0-3 from the currently bound VAO With current in-use shader
  glDrawArrays(#GL_TRIANGLES, 0, 3);
   
  ;SwapBuffers_(hdc)
  ;Delay(16)
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Until WindowEvent() = #PB_Event_CloseWindow


The two Free* functions are not really needed in this simple case, but anyway ...

Re: Modern OpenGL examples with OpenGLGadget

Posted: Thu Jun 26, 2014 1:56 am
by luis
addendum

The code above to test for the opengl version it's not really reliable, since the format of the string it's probably not 100% reliable even if it should be:
GL_VERSION​ Returns a version or release number.

The GL_VERSION​ string begin with a version number. The version number uses one of these forms:

major_number.minor_number
or
major_number.minor_number.release_number

Vendor-specific information may follow the version number. Its format depends on the implementation, but a space always separates the version number and the vendor-specific information.
and yet I found on linux a driver reporting its version this way:

1.4 (3.0 Mesa 10.1.0)

This is wrong in my opinion, since it starts with something it not should be there. 1.4 it's the GLX version number, not the opengl number.
The version number starts with the 3.0 between parenthesis.

I saw tons of code doing the same test I made above, but it seems thanks to some misuse by some vendors this is not 100% reliable.




A better approach is to test at the startup of your program not for the gl version but for the features your program is about to need.
So you could check for the arb extensions corresponding to the core functions present in the version you are targeting. the good thing is they could be there even if the gl version is actually lower, and your program will work anyway.
An alternative I'm exploring is to check for all the entry points of the core functions that should be present in a specifc version. If all the entry points are not null, you can tag the corresponding version as available (becasue the driver does really support that opengl version or because the functions are supported anyway through one ore more extensions).
I have to experiment a little...

Re: Modern OpenGL examples with OpenGLGadget

Posted: Sat Jun 28, 2014 1:01 am
by luis
I made some experiments and digging about the way OpenGL commands can be imported on Win and Linux, to see if there are differences one must consider. I have found some interesting things so far. In no particular order:

*WIN* wglGetProcAddress() return the address for GL functions and GL extensions, but not for the GL functions <= OPENGL_1_1 (return NULL for those)

*WIN* wglGetProcAddress() return NULL if the specified function is not found.

*LIN* glXGetProcAddress() return the address for GL functions and GL extensions, even for GL functions <= OPENGL_1_1

*LIN* The linux OpenGL ABI requires that all libGL implementations on linux export glXGetProcAddressARB, so it's better to import glXGetProcAddressARB and not glXGetProcAddress which may or may not be there

*LIN* glXGetProcAddress() does not require a valid RC to work, probably one reason is because some GLX functions are accessible only through glxGetProcAddress() and another is probably the fact the libGL and the actual driver are more separated than on Windows, and there is some kind of vtable glxGetProcAddress let grow up everytime is invoked that will be filled up by the actual driver later on... (see below)

*LIN* This is something I saw used the wrong way in much code available online. glXGetProcAddress() does not return NULL when the specified function is not found, unless you are asking for a GLX function. For GL functions it always return a pointer. The pointer is routed to the appropriate GL function in the driver when the RC ihas been created, and if one of the functions is not present in the driver calling the function you THINK you have imported through glXGetProcAddress() will crash the program.
Some drivers, notably nVidia to my direct experience, does not do that, just to add confusion. Probably because the implementation of the libGL made by nVidia does know it can work only with nVidia cards and so if you are requesting the *fp for a GL function and it knows it has not been implemented on its hardware it can return NULL. The more generic one made by Mesa can't do the same.

*WIN* wglGetProcAddress() requires a valid RC. Theoretically, the returned pointers are context specific, and also dependent on the pixel format selected.
In practice, for two contexts created on the same machine (same driver vendor and same GPU) then the function pointers will be the same and the same set of functions will be exposed. At least this is my experience and it's also confirmed by what I've found online.
This is probably a consequence of the fact on Windows sometime you need to create a dummy context to be able to access some functions available only when a RC is present, in order to use them to create the actual context you are going to use (for example wglCreateContextAttribs for core profiles, or to select a pixel format supporting multisample, etc.).

All these different behaviors can cause bad assumptions based on the behavior of one specific platform and from what I saw there is some code out there relying on some wrong things...

Hope this is correct and that can be of help, this certainly complicates things.

Re: Modern OpenGL examples with OpenGLGadget

Posted: Sat Jun 28, 2014 8:49 am
by applePi
Hi luis, i have found Extension Viewer here
https://sites.google.com/site/opengltut ... ion-viewer
it shows what is not implemented extensions, it shows that my card GT 520 support up to opengl v 4.1, it has a save button to save the info file.
i wonder who decide the policies for the opengl development in this way or another and force its attitude may be while smoking a cigarette in a cafe, a universities research by professors ? or the nvidea !!
any way i have found the wikibooks are very suitable for plotting the 3d points and related lessons and will try to copy it for purebasic
http://en.wikibooks.org/wiki/OpenGL_Pro ... ntific_arc
http://en.wikibooks.org/wiki/OpenGL_Programming
http://www.swiftless.com/opengl4tuts.html
http://www.rastertek.com/gl40tut03.html
http://www.arcsynthesis.org/gltut/index.html
http://www.arcsynthesis.org/gltut/Basic ... ction.html
http://antongerdelan.net/opengl/index.html
https://vec.io/posts/head-to-opengl-hello-triangle
http://www.theamazingking.com/ogl-vbo.php
http://www.opengl-tutorial.org/beginner ... -triangle/
http://www.lighthouse3d.com/opengl/maths/

Re: Modern OpenGL examples with OpenGLGadget

Posted: Sat Jun 28, 2014 10:40 am
by luis
Thanks for the links :wink:

Re: Modern OpenGL examples with OpenGLGadget

Posted: Fri Jul 04, 2014 11:46 am
by applePi
How to plot your data in 3D space ?
a very abridged version of the example found here http://en.wikibooks.org/wiki/OpenGL_Pro ... utorial_04
just plug in your data from a file or from a function like here, a mexican hat curve
Image
but if you want a round mexican hat then uncomment lines 44, 45, 56
Image

this is like the real hat:
Image

if you want to plot Pointes and not lines change line 84 from
glDrawArrays_(#GL_LINE_STRIP,....
to
glDrawArrays_(#GL_POINTS,...

to make the graph near of far change the -2 to other number in line 69: glTranslatef_(0.0, 0.0, -2)
to disable rotation comment line 77: glRotatef_(rot, 1, 1, 0);
there is a possibility to add keyboard and mouse functions , still haven't tried it, but it is documented in the manual

you may wonder where is the grid instead the vertical lines, i will post this once succeeded since here we need to use indices to the vertices.

Code: Select all

Structure Point3D
  x.f
  y.f
  z.f
  r.f
  g.f
  b.f
EndStructure


Define event, quit

OpenWindow(0, 0, 0, 800, 600, "OpenGL demo .. Mexican Hat Curve")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 20, 10, WindowWidth(0)-40 , WindowHeight(0)-20)

glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glTranslatef_(0, 0, -5)
glEnable_(#GL_DEPTH_TEST)


NbX = 100
NbZ = 100

Dim Point3D.Point3D(NbX,NbZ)

xMin.f = -2 : yMin.f = -2: zMin.f = -2 : xMax.f = 2: yMax = 2 : zMax = 2
;xMin.f = -1 : yMin.f = -1: zMin.f = -1 : xMax.f = 1: yMax = 1 : zMax = 1
;xMin.f = -10 : yMin.f = -10: zMin.f = -10 : xMax.f = 10: yMax = 10 : zMax = 10
;xMin.f = -30 : yMin.f = -30: zMin.f = -30 : xMax.f = 30: yMax = 30 : zMax = 30
;xMin.f = -0.5 : zMin.f = -0.5 : xMax.f = 0.5: zMax = 0.5
  range = xMax - xMin
  step1.f = range / NbX
  x.f = xMin: z.f = zMin : y.f = yMin : v.l = 0
  For b=0 To NbZ
   
    For a=0 To NbX
    
      ;y.f = Sin(10*(x*x+z*z))/5
      y.f =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ; Mexican Hat
      
      ;distance.f = Sqr(Pow((0-x),2) + Pow((0-z),2)) ; distance between plotted point and center 0,0
      ;If distance <= 2.0
      
      Point3D(a,b)\x = x*1
      Point3D(a,b)\y = y*1
      Point3D(a,b)\z = z*1
      
      If y>=0
        Point3D(a,b)\r = 1.0 :Point3D(a,b)\g = 0.3 :Point3D(a,b)\b = 0 
        Else
        Point3D(a,b)\r = 0.7 :Point3D(a,b)\g = 0.8 :Point3D(a,b)\b = 0 
      EndIf
    ;EndIf
      
      x.f + step1
      v+1 ; the index of the vertex (point)
    Next a
    
    x = xMin
    z.f + step1
  Next b
  arrayLength = ArraySize(Point3D())
  
 ;=================================================================================
rot.f = 1
glTranslatef_(0.0, 0.0, -2)
Repeat
  
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  ;glClearColor_(1.0, 1.0, 1.0, 1)
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glEnableClientState_(#GL_VERTEX_ARRAY )
  glEnableClientState_(#GL_COLOR_ARRAY)
  glRotatef_(rot, 1, 1, 0);
 
  glVertexPointer_(3, #GL_FLOAT,SizeOf(Point3D),Point3D(0,0))
  glColorPointer_(3, #GL_FLOAT, SizeOf(Point3D), @Point3D(0,0)\r)
  
  
  For i = 0 To NbX
     glDrawArrays_(#GL_LINE_STRIP, (NbX+1) * i, NbX)
  Next

  glDisableClientState_(#GL_VERTEX_ARRAY);
  glDisableClientState_(#GL_COLOR_ARRAY)
  
 Repeat
    event = WindowEvent()
    If event = #PB_Event_CloseWindow
      quit = #True
    EndIf
  Until event = 0 Or quit = #True
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
  Delay(10)
Until quit = #True
the following are the same but using one dimentional array suitable for the study
remember to uncomment glPointSize_(6) and to used #GL_Points instead of #GL_LINE_STRIP if you want Big points

Code: Select all

Structure Point3D
  x.f
  y.f
  z.f
EndStructure

Structure Colors
  r.f
  g.f
  b.f
EndStructure

Define event, quit

OpenWindow(0, 0, 0, 800, 600, "OpenGL demo .. Mexican Hat Curve")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 20, 10, WindowWidth(0)-40 , WindowHeight(0)-20)

glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glTranslatef_(0, 0, -5)
glEnable_(#GL_DEPTH_TEST)

resolution = 31*31
NbX = 30
NbZ = 30

Dim Point3D.Point3D(31*31)
Dim color.Colors(resolution)

xMin.f = -2 : yMin.f = -2: zMin.f = -2 : xMax.f = 2: yMax = 2 : zMax = 2
;xMin.f = -1 : yMin.f = -1: zMin.f = -1 : xMax.f = 1: yMax = 1 : zMax = 1
;xMin.f = -10 : yMin.f = -10: zMin.f = -10 : xMax.f = 10: yMax = 10 : zMax = 10
;xMin.f = -30 : yMin.f = -30: zMin.f = -30 : xMax.f = 30: yMax = 30 : zMax = 30
;xMin.f = -0.5 : zMin.f = -0.5 : xMax.f = 0.5: zMax = 0.5
  range = xMax - xMin
  step1.f = range / NbX
  x.f = xMin: z.f = zMin : y.f = yMin : v.l = 0
  For b=0 To NbZ
   
    For a=0 To NbX
    
      ;y.f = Sin(10*(x*x+z*z))/5
      y.f =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ; Mexican Hat
      
      Point3D(v)\x = x*1
      Point3D(v)\y = y*1
      Point3D(v)\z = z*1
      
      If y>=0
        color(v)\r = 1.0 :color(v)\g = 0.3 :color(v)\b = 0 
        Else
        color(v)\r = 0.7 :color(v)\g = 0.8 :color(v)\b = 0 
      EndIf
          
      x.f + step1
      v+1 ; the index of the vertex (point)
    Next a
    
    x = xMin
    z.f + step1
  Next b
  arrayLength = ArraySize(Point3D())
  
  ;=================================================================================
rot.f = 1
glTranslatef_(0.0, 0.0, -2)
Repeat
  
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  ;glClearColor_(1.0, 1.0, 1.0, 1)
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glEnableClientState_(#GL_VERTEX_ARRAY )
  glEnableClientState_(#GL_COLOR_ARRAY)
  glRotatef_(rot, 1, 1, 0);
  
  glColorPointer_(3, #GL_FLOAT, 0, color(0))
  ;glPointSize_(6)
  
  For i = 0 To NbX
    glVertexPointer_(3, #GL_FLOAT,0,Point3D(0))
    glDrawArrays_(#GL_LINE_STRIP, 31 * i, 31)
    
  Next

  glDisableClientState_(#GL_VERTEX_ARRAY);
  glDisableClientState_(#GL_COLOR_ARRAY)
  
 Repeat
    event = WindowEvent()
    If event = #PB_Event_CloseWindow
      quit = #True
    EndIf
  Until event = 0 Or quit = #True
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
  Delay(10)
Until quit = #True
Image

any ideas, corrections, notes, are welcome

Re: Modern OpenGL examples with OpenGLGadget

Posted: Fri Jul 04, 2014 12:16 pm
by DK_PETER
Even though, I have no interest in programming using OpenGL commands, it looks really good.
Good going, Applepi :-)

Re: Modern OpenGL examples with OpenGLGadget

Posted: Fri Jul 04, 2014 12:26 pm
by luis
I have one quick note :)
Thanks for the examples as opengl code is always appreciated (at least by me) but maybe you should post them each one on its own thread with some remarks on the top, like: this one requires opengl 1.1, this one requires opengl 3.3, this one does use deprecated commands (nothing wrong with that), this one just use core commands, etc.
Because, for example, you named this thread "Modern OpenGL examples with OpenGL gadget" and your last examples are using deprecated commands.
This could create confusion in beginners.

Hoping there are no errors, I've put together a list of the 1.1 deprecated functions:

Code: Select all

glAccum(a.i,b.f) 
glAlphaFunc(a.i,b.f) 
glAreTexturesResident(a.i,b.i,c.i) 
glArrayElement(a.i) 
glBegin(a.i) 
glBitmap(a.i,b.i,c.f,d.f,e.f,f.f,g.i) 
glCallList(a.i) 
glCallLists(a.i,b.i,c.i) 
glClearAccum(a.f,b.f,c.f,d.f) 
glClearIndex(a.f) 
glClipPlane(a.i,b.i) 
glColor3b(a.a,b.a,c.a) 
glColor3bv(a.i) 
glColor3d(a.d,b.d,c.d) 
glColor3dv(a.i) 
glColor3f(a.f,b.f,c.f) 
glColor3fv(a.i) 
glColor3i(a.i,b.i,c.i) 
glColor3iv(a.i) 
glColor3s(a.w,b.w,c.w) 
glColor3sv(a.i) 
glColor3ub(a.a,b.a,c.a) 
glColor3ubv(a.a) 
glColor3ui(a.i,b.i,c.i) 
glColor3uiv(a.i) 
glColor3us(a.w,b.w,c.w) 
glColor3usv(a.i) 
glColor4b(a.a,b.a,c.a,d.a) 
glColor4bv(a.i) 
glColor4d(a.d,b.d,c.d,d.d) 
glColor4dv(a.i) 
glColor4f(a.f,b.f,c.f,d.f) 
glColor4fv(a.i) 
glColor4i(a.i,b.i,c.i,d.i) 
glColor4iv(a.i) 
glColor4s(a.w,b.w,c.w,d.w) 
glColor4sv(a.i) 
glColor4ub(a.a,b.a,c.a,d.a) 
glColor4ubv(a.a) 
glColor4ui(a.i,b.i,c.i,d.i) 
glColor4uiv(a.i) 
glColor4us(a.w,b.w,c.w,d.w) 
glColor4usv(a.i) 
glColorMaterial(a.i,b.i) 
glColorPointer(a.i,b.i,c.i,d.i) 
glCopyPixels(a.i,b.i,c.i,d.i,e.i) 
glDeleteLists(a.i,b.i) 
glDisableClientState(a.i) 
glDrawPixels(a.i,b.i,c.i,d.i,e.i) 
glEdgeFlag(a.c) 
glEdgeFlagPointer(a.i,b.i) 
glEdgeFlagv(a.i) 
glEnableClientState(a.i) 
glEnd() 
glEndList() 
glEvalCoord1d(a.d) 
glEvalCoord1dv(a.i) 
glEvalCoord1f(a.f) 
glEvalCoord1fv(a.i) 
glEvalCoord2d(a.d,b.d) 
glEvalCoord2dv(a.i) 
glEvalCoord2f(a.f,b.f) 
glEvalCoord2fv(a.i) 
glEvalMesh1(a.i,b.i,c.i) 
glEvalMesh2(a.i,b.i,c.i,d.i,e.i) 
glEvalPoint1(a.i) 
glEvalPoint2(a.i,b.i) 
glFeedbackBuffer(a.i,b.i,c.i) 
glFogf(a.i,b.f) 
glFogfv(a.i,b.i) 
glFogi(a.i,b.i) 
glFogiv(a.i,b.i) 
glFrustum(a.d,b.d,c.d,d.d,e.d,f.d) 
glGenLists(a.i) 
glGetClipPlane(a.i,b.i) 
glGetLightfv(a.i,b.i,c.i) 
glGetLightiv(a.i,b.i,c.i) 
glGetMapdv(a.i,b.i,c.i) 
glGetMapfv(a.i,b.i,c.i) 
glGetMapiv(a.i,b.i,c.i) 
glGetMaterialfv(a.i,b.i,c.i) 
glGetMaterialiv(a.i,b.i,c.i) 
glGetPixelMapfv(a.i,b.i) 
glGetPixelMapuiv(a.i,b.i) 
glGetPixelMapusv(a.i,b.i) 
glGetPolygonStipple(a.i) 
glGetTexEnvfv(a.i,b.i,c.i) 
glGetTexEnviv(a.i,b.i,c.i) 
glGetTexGendv(a.i,b.i,c.i) 
glGetTexGenfv(a.i,b.i,c.i) 
glGetTexGeniv(a.i,b.i,c.i) 
glIndexMask(a.i) 
glIndexPointer(a.i,b.i,c.i) 
glIndexd(a.d) 
glIndexdv(a.i) 
glIndexf(a.f) 
glIndexfv(a.i) 
glIndexi(a.i) 
glIndexiv(a.i) 
glIndexs(a.w) 
glIndexsv(a.i) 
glIndexub(a.a) 
glIndexubv(a.a) 
glInitNames() 
glInterleavedArrays(a.i,b.i,c.i) 
glIsList(a.i) 
glLightModelf(a.i,b.f) 
glLightModelfv(a.i,b.i) 
glLightModeli(a.i,b.i) 
glLightModeliv(a.i,b.i) 
glLightf(a.i,b.i,c.f) 
glLightfv(a.i,b.i,c.i) 
glLighti(a.i,b.i,c.i) 
glLightiv(a.i,b.i,c.i) 
glLineStipple(a.i,b.w) 
glListBase(a.i) 
glLoadIdentity() 
glLoadMatrixd(a.i) 
glLoadMatrixf(a.i) 
glLoadName(a.i) 
glMap1d(a.i,b.d,c.d,d.i,e.i,f.i) 
glMap1f(a.i,b.f,c.f,d.i,e.i,f.i) 
glMap2d(a.i,b.d,c.d,d.i,e.i,f.d,g.d,h.i,i.i,j.i) 
glMap2f(a.i,b.f,c.f,d.i,e.i,f.f,g.f,h.i,i.i,j.i) 
glMapGrid1d(a.i,b.d,c.d) 
glMapGrid1f(a.i,b.f,c.f) 
glMapGrid2d(a.i,b.d,c.d,d.i,e.d,f.d) 
glMapGrid2f(a.i,b.f,c.f,d.i,e.f,f.f) 
glMaterialf(a.i,b.i,c.f) 
glMaterialfv(a.i,b.i,c.i) 
glMateriali(a.i,b.i,c.i) 
glMaterialiv(a.i,b.i,c.i) 
glMatrixMode(a.i) 
glMultMatrixd(a.i) 
glMultMatrixf(a.i) 
glNewList(a.i,b.i) 
glNormal3b(a.a,b.a,c.a) 
glNormal3bv(a.i) 
glNormal3d(a.d,b.d,c.d) 
glNormal3dv(a.i) 
glNormal3f(a.f,b.f,c.f) 
glNormal3fv(a.i) 
glNormal3i(a.i,b.i,c.i) 
glNormal3iv(a.i) 
glNormal3s(a.w,b.w,c.w) 
glNormal3sv(a.i) 
glNormalPointer(a.i,b.i,c.i) 
glOrtho(a.d,b.d,c.d,d.d,e.d,f.d) 
glPassThrough(a.f) 
glPixelMapfv(a.i,b.i,c.i) 
glPixelMapuiv(a.i,b.i,c.i) 
glPixelMapusv(a.i,b.i,c.i) 
glPixelTransferf(a.i,b.f) 
glPixelTransferi(a.i,b.i) 
glPixelZoom(a.f,b.f) 
glPolygonStipple(a.i) 
glPopAttrib() 
glPopClientAttrib() 
glPopMatrix() 
glPopName() 
glPrioritizeTextures(a.i,b.i,c.i) 
glPushAttrib(a.i) 
glPushClientAttrib(a.i) 
glPushMatrix() 
glPushName(a.i) 
glRasterPos2d(a.d,b.d) 
glRasterPos2dv(a.i) 
glRasterPos2f(a.f,b.f) 
glRasterPos2fv(a.i) 
glRasterPos2i(a.i,b.i) 
glRasterPos2iv(a.i) 
glRasterPos2s(a.w,b.w) 
glRasterPos2sv(a.i) 
glRasterPos3d(a.d,b.d,c.d) 
glRasterPos3dv(a.i) 
glRasterPos3f(a.f,b.f,c.f) 
glRasterPos3fv(a.i) 
glRasterPos3i(a.i,b.i,c.i) 
glRasterPos3iv(a.i) 
glRasterPos3s(a.w,b.w,c.w) 
glRasterPos3sv(a.i) 
glRasterPos4d(a.d,b.d,c.d,d.d) 
glRasterPos4dv(a.i) 
glRasterPos4f(a.f,b.f,c.f,d.f) 
glRasterPos4fv(a.i) 
glRasterPos4i(a.i,b.i,c.i,d.i) 
glRasterPos4iv(a.i) 
glRasterPos4s(a.w,b.w,c.w,d.w) 
glRasterPos4sv(a.i) 
glRectd(a.d,b.d,c.d,d.d) 
glRectdv(a.i,b.i) 
glRectf(a.f,b.f,c.f,d.f) 
glRectfv(a.i,b.i) 
glRecti(a.i,b.i,c.i,d.i) 
glRectiv(a.i,b.i) 
glRects(a.w,b.w,c.w,d.w) 
glRectsv(a.i,b.i) 
glRenderMode(a.i) 
glRotated(a.d,b.d,c.d,d.d) 
glRotatef(a.f,b.f,c.f,d.f) 
glScaled(a.d,b.d,c.d) 
glScalef(a.f,b.f,c.f) 
glSelectBuffer(a.i,b.i) 
glShadeModel(a.i) 
glTexCoord1d(a.d) 
glTexCoord1dv(a.i) 
glTexCoord1f(a.f) 
glTexCoord1fv(a.i) 
glTexCoord1i(a.i) 
glTexCoord1iv(a.i) 
glTexCoord1s(a.w) 
glTexCoord1sv(a.i) 
glTexCoord2d(a.d,b.d) 
glTexCoord2dv(a.i) 
glTexCoord2f(a.f,b.f) 
glTexCoord2fv(a.i) 
glTexCoord2i(a.i,b.i) 
glTexCoord2iv(a.i) 
glTexCoord2s(a.w,b.w) 
glTexCoord2sv(a.i) 
glTexCoord3d(a.d,b.d,c.d) 
glTexCoord3dv(a.i) 
glTexCoord3f(a.f,b.f,c.f) 
glTexCoord3fv(a.i) 
glTexCoord3i(a.i,b.i,c.i) 
glTexCoord3iv(a.i) 
glTexCoord3s(a.w,b.w,c.w) 
glTexCoord3sv(a.i) 
glTexCoord4d(a.d,b.d,c.d,d.d) 
glTexCoord4dv(a.i) 
glTexCoord4f(a.f,b.f,c.f,d.f) 
glTexCoord4fv(a.i) 
glTexCoord4i(a.i,b.i,c.i,d.i) 
glTexCoord4iv(a.i) 
glTexCoord4s(a.w,b.w,c.w,d.w) 
glTexCoord4sv(a.i) 
glTexCoordPointer(a.i,b.i,c.i,d.i) 
glTexEnvf(a.i,b.i,c.f) 
glTexEnvfv(a.i,b.i,c.i) 
glTexEnvi(a.i,b.i,c.i) 
glTexEnviv(a.i,b.i,c.i) 
glTexGend(a.i,b.i,c.d) 
glTexGendv(a.i,b.i,c.i) 
glTexGenf(a.i,b.i,c.f) 
glTexGenfv(a.i,b.i,c.i) 
glTexGeni(a.i,b.i,c.i) 
glTexGeniv(a.i,b.i,c.i) 
glTranslated(a.d,b.d,c.d) 
glTranslatef(a.f,b.f,c.f) 
glVertex2d(a.d,b.d) 
glVertex2dv(a.i) 
glVertex2f(a.f,b.f) 
glVertex2fv(a.i) 
glVertex2i(a.i,b.i) 
glVertex2iv(a.i) 
glVertex2s(a.w,b.w) 
glVertex2sv(a.i) 
glVertex3d(a.d,b.d,c.d) 
glVertex3dv(a.i) 
glVertex3f(a.f,b.f,c.f) 
glVertex3fv(a.i) 
glVertex3i(a.i,b.i,c.i) 
glVertex3iv(a.i) 
glVertex3s(a.w,b.w,c.w) 
glVertex3sv(a.i) 
glVertex4d(a.d,b.d,c.d,d.d) 
glVertex4dv(a.i) 
glVertex4f(a.f,b.f,c.f,d.f) 
glVertex4fv(a.i) 
glVertex4i(a.i,b.i,c.i,d.i) 
glVertex4iv(a.i) 
glVertex4s(a.w,b.w,c.w,d.w) 
glVertex4sv(a.i) 
glVertexPointer(a.i,b.i,c.i,d.i) 
gluErrorString(a.i) 
gluErrorUnicodeStringEX(a.i) 
gluGetString(a.i) 
gluOrtho2D(a.d,b.d,c.d,d.d) 
gluPerspective(a.d,b.d,c.d,d.d) 
gluPickMatrix(a.d,b.d,c.d,d.d,e) 
gluLookAt(a.d,b.d,c.d,d.d,e.d,f.d,g.d,h.d,i.d) 
gluProject(a.d,b.d,c.d,d,e,f,g.i,h.i,i.i) 
gluUnProject(a.d,b.d,c.d,d,e,f,g.i,h.i,i.i) 
gluScaleImage(a.i,b.i,c.i,d.i,e.i,f.i,g.i,h.i,i.i) 
gluBuild1DMipmaps(a.i,b.i,c.i,d.i,e.i,f.i) 
gluBuild2DMipmaps(a.i,b.i,c.i,d.i,e.i,f.i,g.i) 
gluNewQuadric() 
gluDeleteQuadric(a.i) 
gluQuadricNormals(a.i,b.i) 
gluQuadricTexture(a.i,b.c) 
gluQuadricOrientation(a.i,b.i) 
gluQuadricDrawStyle(a.i,b.i) 
gluCylinder(a.i,b.d,c.d,d.d,e.i,f.i) 
gluDisk(a.i,b.d,c.d,d.i,e.i) 
gluPartialDisk(a.i,b.d,c.d,d.i,e.i,f.d,g.d) 
gluSphere(a.i,b.d,c.i,d.i) 
gluQuadricCallback(a.i, b.i, c.i) 
gluNewTess() 
gluDeleteTess(a.i) 
gluTessBeginPolygon(a.i,b.i) 
gluTessBeginContour(a.i) 
gluTessVertex(a.i,b,c.i) 
gluTessEndContour(a.i) 
gluTessEndPolygon(a.i) 
gluTessProperty(a.i,b.i,c.d) 
gluTessNormal(a.i,b.d,c.d,d.d) 
gluTessCallback(a.i, b.i, c.i) 
gluGetTessProperty(a.i,b.i,c.i) 
gluNewNurbsRenderer() 
gluDeleteNurbsRenderer(a.i) 
gluBeginSurface(a.i) 
gluBeginCurve(a.i) 
gluEndCurve(a.i) 
gluEndSurface(a.i) 
gluBeginTrim(a.i) 
gluEndTrim(a.i) 
gluPwlCurve(a.i,b.i,c.i,d.i,e.i) 
gluNurbsCurve(a.i,b.i,c.i,d.i,e.i,f.i,g.i) 
gluNurbsSurface(a.i,b.i,c.i,d.i,e.i,f.i,g.i,h.i,i.i,j.i,k.i) 
gluLoadSamplingMatrices(a.i,b,c,d) 
gluNurbsProperty(a.i,b.i,c.f) 
gluGetNurbsProperty(a.i,b.i,c.i) 
gluNurbsCallback(a.i, b.i, c.i) 
gluBeginPolygon(a.i) 
gluNextContour(a.i,b.i) 
gluEndPolygon(a.i) 


You can use them only up to opengl 2.1 or in compatibility mode with later versions.

Also remember with the opengl gadget you are stucked in compatibility mode, so if you write an example requiring 3.3 or higher, it would almost certainly run on Windows with drivers from nVidia / ATI, probably on Linux, and not on OSX, where you can only choose 2.1 for legacy opengl and 3.3 and above with only core commands (no compatibility profile).

That's why would be nice to have the ability to specify version and profile when creating an opengl gadget.

Re: OpenGL examples with OpenGLGadget (modern and old demos)

Posted: Fri Jul 04, 2014 1:19 pm
by applePi
you are right luis i should said it is not modern, even it is a very speedy way of plotting and useful for the busy or traveling men who wants to focus on plotting their data.
and because i will post in the next weeks a mixture of old and modern opengl i have changed the title, i can't post a new thread for every opengl example since it will be lost forever inside the Ogre3D questions, unless there is an Opengl dedicated section inside or outside the 3D section, and this can be Compatible with the introduction of the new OpenGLGadget. then most opengl examples can be moved to that suggested section

Re: OpenGL examples with OpenGLGadget (modern and old demos)

Posted: Fri Jul 04, 2014 5:17 pm
by davido
@applePi, Thank you for these excellent examples. :D

They are very much appreciated.