Paint a rect on qglwidget at specifit times

This is a minimal sample application which mixes OpenGL code and QPainter in paint handler: #include <QtWidgets> #include <QOpenGLFunctions_1_1> // manually added types (normally provided by glib) typedef unsigned guint; typedef unsigned char guint8; extern const struct Image { guint width; guint height; guint bytes_per_pixel; /* 3:RGB, 4:RGBA */ guint8 pixel_data[1]; } fluffyCat; class GLWidget: … Read more

Why is my OBJ parser rendering meshes like this?

I haven’t downloaded your project. What people mostly struggle with when writing OBJ import code for rendering with OpenGL is the indices. And as @ratched_freak also suspects in his comment, that’s very consistent with the visual appearance of your cube. The OBJ format uses separate indices for positions, normals, and texture coordinates. For OpenGL rendering, … Read more

Using GLEW to use OpenGL extensions under Windows

Yes, the OpenGL Extension Wrangler Library (GLEW) is a painless way to use OpenGL extensions on Windows. Here’s how to get started on it: Identify the OpenGL extension and the extension APIs you wish to use. OpenGL extensions are listed in the OpenGL Extension Registry. Check if your graphic card supports the extensions you wish … Read more

Generating a normal map from a height map?

Example GLSL code from my water surface rendering shader: #version 130 uniform sampler2D unit_wave noperspective in vec2 tex_coord; const vec2 size = vec2(2.0,0.0); const ivec3 off = ivec3(-1,0,1); vec4 wave = texture(unit_wave, tex_coord); float s11 = wave.x; float s01 = textureOffset(unit_wave, tex_coord, off.xy).x; float s21 = textureOffset(unit_wave, tex_coord, off.zy).x; float s10 = textureOffset(unit_wave, tex_coord, off.yx).x; … Read more

OpenGL VAO best practices

VAOs act similarly to VBOs and textures with regard to how they are bound. Having a single VAO bound for the entire length of your program will yield no performance benefits because you might as well just be rendering without VAOs at all. In fact it may be slower depending on how the implementation intercepts … Read more

Compute objects moving with arrows and mouse

Here small ugly but very simple C++ example of what I had in mind for this: //————————————————————————— #include <vcl.h> #include <math.h> #pragma hdrstop #include “Unit1.h” #include “gl_simple.h” //————————————————————————— #pragma package(smart_init) #pragma resource “*.dfm” TForm1 *Form1; //————————————————————————— double mview[16],mmodel[16],mproj[16]; // OpenGL matrices //————————————————————————— // vector/matrix math //————————————————————————— double vector_len(double *a) { return sqrt((a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2])); } // = … Read more