Blender Opengl

Posted on  by admin

OpenCL is supported for GPU rendering with AMD graphics cards. Blender supports GPU rendering on graphics cards with GCN generation 2 and above. To make sure your GPU is supported, see the list of GCN generations with the GCN generation and supported graphics cards. Blender is the free and open source 3D creation suite. It supports the entirety of the 3D pipeline—modeling, rigging, animation, simulation, rendering, compositing and motion tracking, video editing and 2D animation pipeline.

  • Loading the OBJ

Until now, we hardcoded our cube directly in the source code. I’m sure you will agree that this was cumbersome and not very handy.

In this tutorial we will learn how to load 3D meshes from files. We will do this just like we did for the textures : we will write a tiny, very limited loader, and I’ll give you some pointers to actual libraries that can do this better that us.

To keep this tutorial as simple as possible, we’ll use the OBJ file format, which is both very simple and very common. And once again, to keep things simple, we will only deal with OBJ files with 1 UV coordinate and 1 normal per vertex (you don’t have to know what a normal is right now).

Our function, located in common/objloader.cpp and declared in common/objloader.hpp, will have the following signature :

We want loadOBJ to read the file “path”, write the data in out_vertices/out_uvs/out_normals, and return false if something went wrong. std::vector is the C++ way to declare an array of glm::vec3 which size can be modified at will: it has nothing to do with a mathematical vector. Just an array, really. And finally, the & means that function will be able to modify the std::vectors.

Example OBJ file

An OBJ file looks more or less like this :

So :

  • # is a comment, just like // in C++
  • usemtl and mtllib describe the look of the model. We won’t use this in this tutorial.
  • v is a vertex
  • vt is the texture coordinate of one vertex
  • vn is the normal of one vertex
  • f is a face

v, vt and vn are simple to understand. f is more tricky. So, for f 8/11/7 7/12/7 6/10/7 :

  • 8/11/7 describes the first vertex of the triangle
  • 7/12/7 describes the second vertex of the triangle
  • 6/10/7 describes the third vertex of the triangle (duh)
  • For the first vertex, 8 says which vertex to use. So in this case, -1.000000 1.000000 -1.000000 (index start to 1, not to 0 like in C++)
  • 11 says which texture coordinate to use. So in this case, 0.748355 0.998230
  • 7 says which normal to use. So in this case, 0.000000 1.000000 -0.000000

These numbers are called indices. It’s handy because if several vertices share the same position, you just have to write one “v” in the file, and use it several times. This saves memory.

The bad news is that OpenGL can’t be told to use one index for the position, another for the texture, and another for the normal. So the approach I took for this tutorial is to make a standard, non-indexed mesh, and deal with indexing later, in Tutorial 9, which will explain how to work around this.

Creating an OBJ file in Blender

Since our toy loader will be severely limited, we have to be extra careful to set the right options when exporting the file. Here’s how it should look in Blender :

Reading the file

Ok, down with the actual code. We need some temporary variables in which we will store the contents of the .obj :

Since Tutorial 5 : A Textured Cube, you know how to open a file :

Let’s read this file until the end :

(notice that we assume that the first word of a line won’t be longer than 128, which is a very silly assumption. But for a toy parser, it’s all right)

Let’s deal with the vertices first :

i.e : If the first word of the line is “v”, then the rest has to be 3 floats, so create a glm::vec3 out of them, and add it to the vector.

i.e if it’s not a “v” but a “vt”, then the rest has to be 2 floats, so create a glm::vec2 and add it to the vector.

Opengl

same thing for the normals :

And now the “f”, which is more difficult :

This code is in fact very similar to the previous one, except that there is more data to read.

Processing the data

So what we did there was simply to change the “shape” of the data. We had a string, we now have a set of std::vectors. But it’s not enough, we have to put this into a form that OpenGL likes. Namely, removing the indexes and have plain glm::vec3 instead. This operation is called indexing.

We go through each vertex ( each v/vt/vn ) of each triangle ( each line with a “f” ) :

the index to the vertex position is vertexIndices[i] :

so the position is temp_vertices[ vertexIndex-1 ] (there is a -1 because C++ indexing starts at 0 and OBJ indexing starts at 1, remember ?) :

Blender Opengl 3.3 Download

And this makes the position of our new vertex

The same is applied for UVs and normals, and we’re done !

Once we’ve got this, almost nothing changes. Instead of declaring our usual static const GLfloat g_vertex_buffer_data[] = {…}, you declare a std::vector vertices instead (same thing for UVS and normals). You call loadOBJ with the right parameters :

and give your vectors to OpenGL instead of your arrays :

And that’s it !

Opengl

Sorry for the lame texture, I’m NOT a good artist :( Any contribution welcome !

This tiny loader should give you enough to get started, but won’t want to use this in real life. Have a look at our Useful Links & Tools page for some tools you can use. Note, however, that you’d better wait for tutorial 9 before *actually *trying to use them.

Blender Opengl

Blender Opengl

Blender 2.8+ and beyond (Blender 2.9+, 3.x, 4.x et al) is as much of a change from version 2.79 as 2.50 was from 2.49, in that significant parts of the internal rendering system has been rewritten to accommodate more modern systems and effects. Unfortunately this mean it may not run when installed to older computers, desktop or laptop alike, unless the graphics sub-systems support OpenGL 3.3 or above.

Blender Opengl

IMPORTANT NOTE: unfortunately Blender 2.8 and above to the latest versions will not run on a “Potato PC” so a bigger potato, or an appropriately sized sack of potatoes, preferably of a red or russet variety, will need to be purchased at some point – sadly there is no way to avoid this recipe requirement without burning everything and setting the kitchen on fire.

Design note: generally speaking Blender not running on a given computer is more likely a hardware, rather than software issue (notwithstanding operating system/driver incompatibilities).

How to check Blender compatibility

To check if the “Unsupported graphics driver” error is the actual problem starting Blender 2.8 or above, first determine the systems graphics capabilities. If this is unknown, type “Device Manager” into the Start menu Search bar (or Cortana) and check the “Display adapters” listing, it should read something like “Intel(R) HD Graphics 3000” for example, that’s mid-second generation Intel CPU (2xxx).

Design note: Intel’s graphics infrastructure is a component of the CPU rather than a separate or dedicated external card as might be provided by nVidia or AMD so the nomenclature used may not be specifically generational as that might otherwise be thought; HD 2000, 3000 and some 4000 subsystems for example, can be found on Intel i3/i5/i7 2nd generation CPU’s (e.g. i3 2330, i5 2500 etc.). For NVIDIA, ATI/AMD, most graphics card from NVIDIA‘s 4th generation (and above) support OpenGL 3.x, this includes ‘m’ or mobile class embedded GPUs, i.e. Geforce 405m supports OpenGL 4.5 (3rd generation or below do not support 3.x). For ATI/AMD, cards/mobile modules based on the R500 GPU support OpenGL 3.x, although preference should be for R600 or above as this supports OpenGl 4.x ensuring greater compatibility.

Using this information search the Internet for details. For the above this might bring up this from Intel itself or this from Wikipedia, the upshot being that Intels HD 3000 only supports OpenGL up to 3.1 on Windows (3.3 on Linux). In this instance Blender 2.8 or any version above that won’t run on Windows 7, 8 or 10 resulting in the error seen.

How to fix the Blender compatibility issue

Notwithstanding driver updates, unfortunately the only way to fix or address the issue and get Blender 2.8+ up and running is to update the systems graphics hardware, the graphics card, onboard chipset or component responsible for rendering graphics to something that’s OpenGL 3.3 compatible. For laptop/notebook users this is generally not possible (unless using an MXM module). For desktop users any modern card manufactured within the last few years should be capable of running Blender 2.8+ (cf. above) but double-check before purchase.

OpenGL, Blender 2.9+ & Beyond

Due to Blenders relatively rapid development support for cutting edge features obligate use of relatively modern graphics cards or systems. As a result Blender 2.90, and going forward to all versions of Blender, a compatible graphics card that supports, at minimum, OpenGL 3.3 as discussed above, is REQUIRED. If not, when launched Blender 2.9 et al will display the same Blender – Unsupported Graphics Card of Driver error message. Unfortunately, again as above, this means a graphics system update will be necessary to run newer versions of the application.

Design note: for Linux users OpenGL 3.3 support may be available depending on driver installed.


Blender 2.9, and going forward ALL VERSIONS of Blender, require graphics support for OpenGL 3.3 or above.

Blender 2.91 Support

Download

With the introduction of Blender 2.91 a new set of minimum requirements have been brought into effect that means support for OpenGL 3.3, on its own, is no longer sufficient to run Blender. For AMD graphics cards used in particular Blender will ‘crash’ on launch briefly displaying an EXCEPTION_ACCESS_VIOLATION error. If this occurs it exposes a hardware incompatibility due to use of an older chip-set architecture that’s obsolete and longer unsupported by AMD, Terascale instead of the newer GCN series. As this issue is hardware related is cannot be solved with driver updates, and obligates a(nother) hardware upgrade to address.

Important: for Blender 2.91 Intel’s HD Graphics 3000 is no longer supported, the minimum is the HD Graphics 4200 chipset (OpenGL 3.3 support remains).

Design note: crash report/log can be found in C:Users[user]AppDataLocalTempblender.crash.txt

Error : EXCEPTION_ACCESS_VIOLATION
Address : 0x000000005B922FB7
Module : atio6axx.dll
Thread : 00002c60
Writing: C:Users[user]AppDataLocalTempblender.crash.txt


Blender 2.91 introduces new requirements to run the application else it will ‘crash’ out briefly displaying a fatal error that means support for OpenGL 3.3 or above is no longer sufficient (despite being so for Blender 2.90.x).