It is currently Wed Sep 18, 2019 7:09 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Looking for OpenGL 4.X (2D) Tutorials!
PostPosted: Thu Jun 13, 2019 5:42 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 514
Im looking for OpenGL 4.X (2D) tutorials.
Please let me know if you know some good ones :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Looking for OpenGL 4.X (2D) Tutorials!
PostPosted: Fri Jun 14, 2019 2:11 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 514
Most of the tutorials i found use GLFW https://www.glfw.org which looks really good.
So i made an PureBasic include for the current version 3.3 (no pain no gain) :)

I first tried to use the static lib but i was not able to remove all linker errors.

What i did to get rid of most of the errors (if someone wants to look into this):
Code:
Import "User32.lib":EndImport
Import "ntdll.lib":EndImport
Import "BufferOverflow.lib":EndImport
Import "BufferOverflowU.lib":EndImport
Import "libcmt.lib":EndImport
;-> POLINK: error Unresolved external symbol '__imp_vsnprintf'


Linking 'legacy_stdio_definitions.lib' did not fix it for me (this was the only solution i found online).
Anways i can use the dll version without issues :P

Now can try some of the GLFW tutorials :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Looking for OpenGL 4.X (2D) Tutorials!
PostPosted: Fri Jun 14, 2019 8:17 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 514
Found a good site that uses GLFW: https://learnopengl.com

I completed the 1st Tutorial 8)

How it looks in PureBasic:
Code:
EnableExplicit

;https://learnopengl.com/Getting-started/Hello-Triangle

XIncludeFile "glfw3.pbi"

Global *window.GLFWwindow

Global vertex_shader.i
Global vertex_shader_string.s
Global *vertex_shader_source
Global vertex_shader_status.i

Global fragment_shader.i
Global fragment_shader_string.s
Global *fragment_shader_source
Global fragment_shader_status.i

Global shader_program.i
Global shader_program_status.i

Global Dim vertices.f(9)
Global vbo.i
Global vao.i

Procedure.i FrameBufferCallback(*window,width.i,height.i)
  glViewport_(0,0,width,height)
EndProcedure

If glfwVersionCheck()
  If glfwInit() = #GLFW_TRUE
    glfwWindowHint(#GLFW_SAMPLES, 4)
    glfwWindowHint(#GLFW_CONTEXT_VERSION_MAJOR,4);<- window setup for opengl 4.X this alone will take ~ 200 lines of code when done manually!
    glfwWindowHint(#GLFW_CONTEXT_VERSION_MINOR,0)
    glfwWindowHint(#GLFW_OPENGL_PROFILE,#GLFW_OPENGL_CORE_PROFILE);
    *window = glfwCreateWindow(800,600,"Test",#Null,#Null)
    If *window
      glfwSetWindowSizeLimits(*window,800,600,#GLFW_DONT_CARE,#GLFW_DONT_CARE)
      glfwMakeContextCurrent(*window)
      If glfwLoadOpenGL();<- load all opengl (4.X) functions!
        glfwSetFramebufferSizeCallback(*window,@FrameBufferCallback())
        glfwSwapInterval(1)
        glfwSetInputMode(*window,#GLFW_STICKY_KEYS,#GLFW_TRUE)
       
        vertex_shader_string = "#version 330 core" + #CRLF$
        vertex_shader_string + "layout (location = 0) in vec3 aPos;"+ #CRLF$
        vertex_shader_string + "void main()"+ #CRLF$
        vertex_shader_string + "{"+ #CRLF$
        vertex_shader_string + "   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);"+ #CRLF$
        vertex_shader_string + "}"
        *vertex_shader_source = Ascii(vertex_shader_string)
        vertex_shader = *glCreateShader(#GL_VERTEX_SHADER)
        *glShaderSource(vertex_shader,1,@*vertex_shader_source,0)
        *glCompileShader(vertex_shader)
        *glGetShaderiv(vertex_shader,#GL_COMPILE_STATUS,@vertex_shader_status);<- error handling!
       
        fragment_shader_string = "#version 330 core" + #CRLF$
        fragment_shader_string + "out vec4 FragColor;" + #CRLF$
        fragment_shader_string + "void main()" + #CRLF$
        fragment_shader_string + "{" + #CRLF$
        fragment_shader_string + "   FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);" + #CRLF$
        fragment_shader_string + "}" + #CRLF$
        *fragment_shader_source = Ascii(fragment_shader_string)
        fragment_shader = *glCreateShader(#GL_FRAGMENT_SHADER)
        *glShaderSource(fragment_shader,1,@*fragment_shader_source,0)
        *glCompileShader(fragment_shader)
        *glGetShaderiv(fragment_shader,#GL_COMPILE_STATUS,@fragment_shader_status);<- error handling!
       
        Debug vertex_shader_status
        Debug fragment_shader_status
       
        shader_program = *glCreateProgram()
        *glAttachShader(shader_program,vertex_shader)
        *glAttachShader(shader_program,fragment_shader)
        *glLinkProgram(shader_program)
        *glGetProgramiv(shader_program,#GL_LINK_STATUS,@shader_program_status);<- error handling!
       
        Debug shader_program_status
       
        *glDeleteShader(vertex_shader)
        *glDeleteShader(fragment_shader)
        FreeMemory(*vertex_shader_source)
        FreeMemory(*fragment_shader_source)
       
        vertices(0) = -0.5
        vertices(1) = -0.5
        vertices(2) = 0
        vertices(3) = 0.5
        vertices(4) = -0.5
        vertices(5) = 0
        vertices(6) = 0
        vertices(7) = 0.5
        vertices(8) = 0
       
        *glGenVertexArrays(1,@vao)
        *glGenBuffers(1,@vbo)
        *glBindVertexArray(vao)
        *glBindBuffer(#GL_ARRAY_BUFFER,vbo)
        *glBufferData(#GL_ARRAY_BUFFER,9 * 4,vertices(),#GL_STATIC_DRAW)
        *glVertexAttribPointer(0,3,#GL_FLOAT,#GL_FALSE,3 * 4,#Null)
        *glEnableVertexAttribArray(0)
       
        *glBindBuffer(#GL_ARRAY_BUFFER,0)
        *glBindVertexArray(0)
       
        *glClearColor(0.2,0.3,0.3,0)
        Repeat
          *glClear(#GL_COLOR_BUFFER_BIT)
         
         
          *glUseProgram(shader_program)
          *glBindVertexArray(vao)
          *glDrawArrays(#GL_TRIANGLES,0,3)
         
          glfwSwapBuffers(*window)
          glfwPollEvents()
        Until glfwGetKey(*window,#GLFW_KEY_ESCAPE) = #GLFW_PRESS Or glfwWindowShouldClose(*window)
      EndIf
      glfwDestroyWindow(*window) 
    EndIf
    glfwTerminate()
  EndIf
 
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Looking for OpenGL 4.X (2D) Tutorials!
PostPosted: Sat Jun 15, 2019 1:54 pm 
Offline
New User
New User

Joined: Thu Sep 20, 2018 12:27 pm
Posts: 6
Thanks for the exemple but where can i find glfw3.pbi


Top
 Profile  
Reply with quote  
 Post subject: Re: Looking for OpenGL 4.X (2D) Tutorials!
PostPosted: Tue Jun 25, 2019 7:56 am 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 983
Location: Germany
ultimzeus wrote:
Thanks for the exemple but where can i find glfw3.pbi

viewtopic.php?f=12&t=73073

@Mijikai: I've got an error: glfwVersionCheck() is not a function..

_________________
"Daddy, I'll run faster, then it is not so far..."


Top
 Profile  
Reply with quote  
 Post subject: Re: Looking for OpenGL 4.X (2D) Tutorials!
PostPosted: Tue Jun 25, 2019 5:30 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 514
dige wrote:
ultimzeus wrote:
Thanks for the exemple but where can i find glfw3.pbi

viewtopic.php?f=12&t=73073

@Mijikai: I've got an error: glfwVersionCheck() is not a function..


I added some helper functions myself glfwLoadOpenGL() for example is also not a function in GLFW.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye