But I have a lot of doubts! I don’t understand which lines go to initialise(), and which ones to render(). I also have problems with shaders source code (apparently #version 330 is not supported). I’ve been trying to solve every issue, but my final result is always a sad black screen.
Do you know about a OpenGL template for JUCE including some basic initialization to draw basic primitives? Let’s say some basic polygons that move along the screen. It would be very helpful!
I second looking at OpenGLAppExample. The code you’re currently working with in your project is the OpenGL template provided by the Projucer right?
To answer some of your specific questions:
initialise() is intended to be used to set up your OpenGL context before entering your render loop. Things that you don’t want to update-per frame (i.e. once) should be set here, like shader loading/compilation/linking, global states like culling and such.
In the specific tutorial, you linked, you want the initialization code to go into the initialise() function, and the “game loop” code to go into the render() function.
One of the biggest things to remember is to not get discouraged. OpenGL is very difficult (MUCH more than it should be), frustrating, and inconsistent, for a number of reasons relating to graphics card manufacturers and the standard’s history. The first big hurdle to getting something cool going to it is getting a context displaying in a window, which luckily JUCE helps us do much faster and better than any other OpenGL windowing library I’ve found (GLFW, GLUT, etc) so you’re on the right track. Be sure to check out the OpenGLHelpers namespace, it has a lot of extremely helpful code that’s normally extremely annoying to have to write for things like shader loading/compilation.
Lastly, I want to leave you with this guy’s YouTube playlist, it’s phenomenal and where I learned OpenGL from, eventually leading me to getting a job writing core rendering code for CAD software:
He uses Qt but all the code is very easy to transfer over to JUCE since the ideas of the interfaces between JUCE and Qt (and most other windowing systems) OpenGL of initialize/render is nearly identical.
I’ve checked the OpenGL examples you mention (Alan’s contribution is especially helpful), thanks! For sure, as soon as I can get started with a simple working example, the resources you mention will be a good way to keep improving quickly. However, still I’m not able to simplify those examples to get what I am looking for: a very basic program drawing a few moving triangles.
I took a look at the code in your repo and oddly, I couldn’t find anything that looked weird. I’m not sure if maybe there’s something wrong with how you’re using the openGLContext functions, as I’ve never used JUCE’s implementation, I always use GLEW (which I would highly recommend, as it’s always up to date with the OpenGL spec and doesn’t require "openGlContext.extensions.*").
Many thanks for your extraordinary example. It is brilliant.
I’m completely new to OpenGL and JUCE and so I decided to take your example as starting point for a project of mine. I’m attempting to replace the teapot with a sphere. I loaded the .obj file into my JUCE project using the BinaryData class and I swapped it for the teapot. Now the issue is that when I launch the app, the texture is applied to the background and not to the object anymore.
How can I apply the texture to the new object?
Many thanks for your contribution,
Following the bit of code where I replaced the teapot with the sphere:
// The obj file could contain multiple objects or groups but in this example // only one object has been used (shapeFile.shapes.size() = 1) if (shapeFile.load (BinaryData::sphere_obj).wasOk()) for (int i = 0; i < shapeFile.shapes.size(); ++i) // Store the ith object info into a vertex buffer which itself is part // of a vertex buffer list. Again here inly one buffer will be used. vertexBuffers.add (new VertexBuffer (openGLContext, *shapeFile.shapes.getUnchecked(i)));
Hey all, I recently made a JUCE OpenGL setup tutorial for rendering basic primitive 3D objects including a triangle, pyramid, and cube. It’s a code-along tutorial video with available source code and some utility classes. It also discusses 2D rendering and other JUCE graphics rendering options.