An demo of how use opengl with juce, anyone want to do it together?

I want to port the tutorial on https://learnopengl.com/ to juce framework.
Current I have done eight tutorial as follows .
https://learnopengl.com/Getting-started/Hello-Triangle
https://learnopengl.com/Getting-started/Shaders
https://learnopengl.com/Getting-started/Textures
https://learnopengl.com/Getting-started/Coordinate-Systems
https://learnopengl.com/Getting-started/Camera
https://learnopengl.com/Lighting/Colors
https://learnopengl.com/Lighting/Basic-Lighting

code:
https://github.com/iomeone/openglWithJuce
pull Request is welcome!

Screen:
Tutorial triangle And Shader


Tutorial multiTexture

Tutorial Coordinate-Systems

Tutorial6:Camera

Tutorial7:Colors

Tutorial8:Basic-Lighting

etc.

15:Model-Loading https://learnopengl.com/Model-Loading/Model

6 Likes

Hi @bzhkl,
Very nice idea :smiley:
Unfortunately I can not contribute now, but I will keep my fingers crossed for this project to grow.

Thank you for sharing.

Awesome idea, too bad I’m on a Mac :laughing:

I’ve update the code, so now we can open openglWithJuce.xcodeproj, compile and run !
But unfortunately , there is some bug with the code or with my graphic card,
when i call glBindVertexArray, it throws GL_INVALID_OPERATION with error code 1282.
I assume it‘s my graphic card bug.
Anyone want help to test, thanks!

I have some OpenGL examples on my GitHub. Maybe they help. The basic one is using the juce::OpenGLContext. The other two are using glew

Thank you for the code , and I can make it running after add the code openGLContext.setOpenGLVersionRequired(juce::OpenGLContext::openGL3_2);
but behave differently from win version as follow image, I’ll look into it.

Hi @bzhkl,

First of all I want to say that you inspired me to learn OpenGL :slight_smile: Thanks.

I found some issue with tutorial 3 and 4 on my macOs.

I digged a bit and I found that this is a problem with translating shaders from version 2 to version 3.
I will create pull request and there describe what I found in more details.

On my windows machine everything works OK.

@ mateusz
Thank you very much , looking forward it , and I will look into it too!

update:
I think it’s tricky.
because shader is compiled successfully and without any error .
And the output info shows that Current glsl version is 4.10 and should support in and out keyword.
I also checked the glversion in initialise function by
AlertWindow::showMessageBox(AlertWindow::AlertIconType::InfoIcon, "glversion", (char*)glGetString(GL_VERSION));
also is 4.10.
I also tried modify juce code
#define JUCE_GLSL_VERSION "#version 150"
to
#define JUCE_GLSL_VERSION "#version 410"
then shader can compile and link without any error , but the demo cube still can’t show .
Anyway your pull request works . I’ll merge and Now I can move forward on my mac .
Thanks!

update:
I finally figure out what’s the fundamental problem. It’s basically how @ mateusz does.
Let’s say tutorial 3. we just change the vertex shader from

attribute vec3  aPos;
attribute vec3  aColor;
attribute vec2  aTexCoord;

to

layout (location=0) in vec3  aPos;
layout (location=1) in vec3  aColor;
layout (location=2) in vec2  aTexCoord;

Which is how original tutorial write. It’s my bad.(originally I want to support old graphic card, but it seems not work! so I want to use glsl version 330 instead)

then We need to specify the glsl version we want to use in shader .
like #version 330 core

I think juce team should give us a chance to specify what’s
GLSL version we want to use , then problem solved!

#if JUCE_OPENGL3

 #if JUCE_OPENGL_ES

#define JUCE_GLSL_VERSION "#version 300 es"

 #else

#define JUCE_GLSL_VERSION "#version 150"

 #endif

#else

 #define JUCE_GLSL_VERSION ""

#endif

we want to customise
#define JUCE_GLSL_VERSION "#version 150" this line to
#define JUCE_GLSL_VERSION "#version 330 core" as we need.

Sorry, I did not described what I have changed in translateVertexShaderToV3 and translateFragmentShaderToV3 methods.

I am glad I helped. :slight_smile:

I made a JUCE OpenGL setup tutorial for rendering basic interactive 3D objects including a triangle, pyramid, and cube. It’s a code-along tutorial video with available source code and some utility classes.

You can access the tutorial for free or pay what you want via Gumroad: https://gum.co/juce-opengl-setup

I thought this might be helpful to those in this thread.
Thanks!