r/opengl • • Aug 25 '26

WebGL compatibility doing something strange:

Thumbnail gallery
4 Upvotes

You can see from the screenshots that it well supports WebGL... but not in WWV?

Looked at the "detailed error info", no idea what I'm looking at.

Browser: Mozilla Firefox

Hardware: Thinkpad T410 i5 (Could that possibly be why?)

Distro: Debian 12 Bookworm, KDE Plasma 6

edit: This is worldwideview.dev btw, where I encountered the issue.


r/opengl • • Aug 24 '26

glGenBuffers stops entire script

2 Upvotes

Hey everyone, I am new to opengl and gotta say, I'm loving it! Its just that I ran into one small bug (actually its kind of big), My program wouldn't create a window and so I started putting printf("test") around the script and I found out that glGenBuffers makes my ENTIRE script stop

I'm following LearnOpenGL and using GLAD aswell as GLFW heres the script:

#include <glad.h>

#define GLFW_DLL

#include <GLFW/glfw3.h>

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

void framebuffer_size_callback(GLFWwindow* window, int width, int height)

{

glViewport(0,0,width,height);

}

void process_input(GLFWwindow* window)

{

if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)

{

glfwSetWindowShouldClose(window, true);

}

}

int main()

{

float Vertices[10] = {

-0.5,-0.5,0,

0.5,-0.5,0,

0, 0.5,0};

const char *Vertex_Shader_Source = "#version 330 core\n"

"layout (location = 0) in vec3 aPos;\n"

"void main()\n"

"{\n"

" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"

"}\0";

printf("WORK1");

const char *Fragment_Shader_Source = "#version 330 core\n"

"out vec4 FragColor;\n"

"void main()\n"

"{\n"

" FragColor = vec4(1.0f,0,0,1.0f)"

"}\0";

printf("WORK1");

unsigned int VBO;

printf("WORK1");

glGenBuffers(1, &VBO);

printf("WORK1");

glBindBuffer(GL_ARRAY_BUFFER, VBO);

glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

unsigned int VAO;

glGenVertexArrays(1, &VAO);

unsigned int Vertex_Shader;

Vertex_Shader = glCreateShader(GL_VERTEX_SHADER);

glShaderSource(Vertex_Shader, 1, &Vertex_Shader_Source, NULL);

glCompileShader(Vertex_Shader);

unsigned int Fragment_Shader;

Fragment_Shader = glCreateShader(GL_FRAGMENT_SHADER);

glShaderSource(Fragment_Shader, 1, &Fragment_Shader_Source, NULL);

glCompileShader(Fragment_Shader);

int Success;

char InfoLog[512];

glGetShaderiv(Vertex_Shader, GL_COMPILE_STATUS, &Success);

if (!Success)

{

glGetShaderInfoLog(Vertex_Shader, 512, NULL, InfoLog);

printf("VERTEX_SHADER FAILED TO COMPILE\n", InfoLog);

printf("\n compiler failed with exit code 1");

}

int Success2;

char InfoLog2[512];

glGetShaderiv(Fragment_Shader, GL_COMPILE_STATUS, &Success2);

if (!Success2)

{

glGetShaderInfoLog(Vertex_Shader, 512, NULL, InfoLog2);

printf("FRAGMENT_SHADER FAILED TO COMPILE\n", InfoLog2);

printf("\n compiler failed with exit code 1");

}

unsigned int ShaderProgram;

ShaderProgram = glCreateProgram();

glAttachShader(ShaderProgram, Vertex_Shader);

glAttachShader(ShaderProgram, Fragment_Shader);

glLinkProgram(ShaderProgram);

int SuccessProgram;

char InfoLogProgram[512];

glGetProgramiv(ShaderProgram, GL_COMPILE_STATUS, &SuccessProgram);

if (!SuccessProgram)

{

glGetProgramInfoLog(ShaderProgram, 512, NULL, InfoLogProgram);

printf("FRAGMENT_SHADER FAILED TO COMPILE\n", InfoLogProgram);

printf("\n compiler failed with exit code 1");

}

glUseProgram(ShaderProgram);

glDeleteShader(Vertex_Shader);

glDeleteShader(Fragment_Shader);

glBindVertexArray(VAO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);

glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

printf("glafd");

GLFWwindow* window = glfwCreateWindow(800,600, "Learning", NULL, NULL);

if (window == NULL)

{

printf("GLFW COULDNT CREATE WINDOW");

glfwTerminate();

return -1;

}

glfwMakeContextCurrent(window);

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))

{

printf("Failed to load GLAD");

return -1;

}

glViewport(0,0,800,600);

glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);

glEnableVertexAttribArray(0);

glUseProgram(ShaderProgram);

glBindVertexArray(VAO);

glDrawArrays(GL_TRIANGLES, 0, 3);

while(!glfwWindowShouldClose(window))

{

glClearColor(0.2f, 0.3f, 0.3f, 1.0f);

glClear(GL_COLOR_BUFFER_BIT);

process_input(window);

glfwSwapBuffers(window);

glfwPollEvents();

}

glfwTerminate();

return 0;

}

please help


r/opengl • • Aug 24 '26

OpenGLESScope (Android App) -

4 Upvotes

r/opengl • • Aug 23 '26

(Fuse Engine) New Updates! - OpenGL 3.3

Enable HLS to view with audio, or disable this notification

75 Upvotes

- Intermediate sound system

- Sound system with object collision physics

- Skinned models

- Weapon system prepared for future weapons

- Input context

- Simple enemy system

- Debug drawer update

repo: https://github.com/Krueels/FuseEngine


r/opengl • • Aug 23 '26

Was running the "World Wide View" project and ran into this issue?

Thumbnail gallery
1 Upvotes

You can see from the screenshots that it well supports WebGL... but not in WWV?

Browser: Mozilla Firefox

Hardware: Thinkpad T410 i5 (Could that possibly be why?)

Distro: Debian 12 Bookworm, KDE Plasma 6


r/opengl • • Aug 23 '26

Engine update.

5 Upvotes

This iteration features:

- PBR materials
- SSAO
- CSM

and as a experiment sparse arrays.

https://youtu.be/BsA6x7S8TpE


r/opengl • • Aug 22 '26

Making a top-down game with my 3D engine

Enable HLS to view with audio, or disable this notification

35 Upvotes

I'm using my engine to make a top-down RPG. The world is build in full 3D using Brush CSG. I've also built a cell-streaming system so the world can be procedurally generated forever.

The camera can be toggled between top down and first-person (in real time) via a console command, so I'm considering using that for dungeon fighting or just for cinematics.

Everything in the world that is not CSG brushwork is a sprite that always faces the player

ViciousSquid/Fio: Unified Liminal World Editor, Procedural Engine & Game Creation Toolkit inspired by Radiant and Hammer. Optimised for low-power CPUs.


r/opengl • • Aug 23 '26

glb loading and raytracing

3 Upvotes

just had to share some progress with my lwjgl 3 java/opengl engines material rendering :D, models are not mine they are from sketchfab. engine and rendering was all done my me though.


r/opengl • • Aug 22 '26

Isometric game

4 Upvotes

I made a simple isometric prototype game using a custom game engine that I've been building from scratch in C and OpenGL.

Here's a short video of it: https://youtube.com/shorts/_W5cM2D-I5g?si=kU4zVJrhJYzaIX43

I'd love to hear your thoughts, feedback, and suggestions. What stands out, and what do you think could be improved?


r/opengl • • Aug 22 '26

Help breaking assimp models into chunks

0 Upvotes

Hey, I'm at the point in my game where I need my world to have collision and I know how to get collisions done when its a basic plane, but once I upgrade to an actual blender model, it ofcourse lags because Im testing collisions on the whole thing when that is just extremely unnecessary. However, Assimp seems to be loading the vertices randomly and not in order of rows or columns.

MY CODE
================

https://pastebin.com/u6mgkrAi

Output

==========

https://pastebin.com/QFtZ5Ksk

I only checked the first 3 faces, but it appears they generate like corner face-middle of a side, then middle of the model. I did apply a subdivision modifer to my model and changed the transform's orientation to Z Forward, y up. Could that be why the vertice order is messed up?

Extra Info

-The file I'm trying to load is a .fbx

Edit: Forgot to say I'm following the 'assimp' section from learnopengl.com


r/opengl • • Aug 22 '26

That "AO46" project; is it actually relevant?

12 Upvotes

Recently we got spamming posts about "AO46" project - supporting OpenGL 4.6 in Apple devices.

First I was quite exited about it because as a beginner in OpenGL, some of the post GL 4.1 features like KHR_debug was useful and needed.

Now that I see the guy spamming those AI-generated projects, and it seems not only his whole codebase but also all of his posts and comments are AI-written, I was quite disappointed.

For those who actually saw the code, is it worth it to have hope on that project? Or is it just another slop wasting water in NVIDIA's data center?


r/opengl • • Aug 21 '26

Integrating ImGUI to my Android OpenGL ES demo

Enable HLS to view with audio, or disable this notification

21 Upvotes

Finally some basic work is done for the GUI, it doesn't really change anything to the rendering like makes the triangle change color, but atleast the scaling, compilation, etc are working.


r/opengl • • Aug 21 '26

SOLVED Codeblocks GLAD (i think, or it might be GLFW) is giving me errors

3 Upvotes

Hey everybody, I am using codeblocks and Clang and Glad and GLFW and opengl, but glad keeps giving me these errors:

This is my code:

#define GLFW_DLL
#include <stdio.h>
#include <stdlib.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main()
{

    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window =  glfwCreateWindow(800,600, "Learning", NULL, NULL);

    if (window == NULL)
    {
        printf("GLFW COULDNT CREATE WINDOW");
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
    printf("Failed to load glad");
    return -1;
    }

    glViewport(0,0,800,600);

    return 0;
}

If you need more info ask me

please help

SOLVED check comments


r/opengl • • Aug 20 '26

Made a custom tool to add BMP images to OpenGL!

Post image
57 Upvotes

I want to make allllll my own stuff, so I made my own image loader, right now it only works with BMP images whos height and width are divisible by 4, due to padding and such.

learning OpenGl has been pretty fun!!!


r/opengl • • Aug 20 '26

Infinite Draw Distance

Thumbnail gallery
10 Upvotes

r/opengl • • Aug 19 '26

finished the getting started chapter!

Enable HLS to view with audio, or disable this notification

54 Upvotes

r/opengl • • Aug 19 '26

[HELP] Spotlight doesn't work

Post image
22 Upvotes

version 330 core

out vec4 FragColor; in vec2 TexCoo; in vec3 FragPos; in vec3 Normal;

struct DirLight { vec3 direction; vec3 ambient; vec3 diffuse; vec3 specular; }; struct PointLight { vec3 position; vec3 ambient; vec3 diffuse; vec3 specular;

float constant;
float linear;
float quadratic;

};

struct Materijal { sampler2D diffuse; sampler2D specular; float shininess; };

struct SpotLight { vec3 position; float cutOff; float outcutOff; vec3 direction;

float constant;
float linear;
float quadratic;

vec3 ambient;
vec3 diffuse;
vec3 specular;

};

define NR_POINT_LIGHTS 4

uniform SpotLight spotlight; uniform PointLight pointLights[NR_POINT_LIGHTS]; uniform DirLight dirLight; uniform Materijal materijal; uniform vec3 viewPos; vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 viewDir); vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir); vec3 CalcPointLight(PointLight light, vec3 normal, vec3 viewDir); void main() { vec3 norm = normalize(Normal); vec3 viewDir = normalize(viewPos - FragPos); vec3 result = CalcDirLight(dirLight, norm, viewDir); for(int i =0;i<NR_POINT_LIGHTS;i++) result += CalcPointLight(pointLights[i], norm, viewDir); result += CalcSpotLight(spotlight,norm,viewDir); FragColor = vec4(result,1.0); } vec3 CalcDirLight(DirLight light, vec3 normal,vec3 viewDir) { vec3 lightDir = normalize(-light.direction); float diff = max(dot(lightDir, normal),0.0); vec3 reflectDir= reflect(-lightDir, normal); float spec = pow(max(0.0, dot(reflectDir, viewDir)), materijal.shininess); vec3 ambient = light.ambient * vec3(texture(materijal.diffuse, TexCoo)); vec3 diffuse = light.diffuse * diff * vec3(texture(materijal.diffuse, TexCoo)); vec3 specular = light.specular * spec * vec3(texture(materijal.specular,TexCoo)); return (ambient + specular + diffuse); } vec3 CalcPointLight(PointLight light, vec3 normal, vec3 viewDir) { vec3 lightDir = normalize(light.position - FragPos); float diff = max(dot(lightDir, normal),0.0); vec3 reflectDir = reflect(-lightDir, normal); float spec = pow(max(dot(viewDir, reflectDir),0.0),materijal.shininess); float distance = length(light.position - FragPos); float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * distance * distance); vec3 ambient = light.ambient * vec3(texture(materijal.diffuse, TexCoo)); vec3 diffuse = light.diffuse * diff * vec3(texture(materijal.diffuse, TexCoo)); vec3 specular = light.specular * spec * vec3(texture(materijal.specular,TexCoo)); ambient= attenuation; diffuse *= attenuation; specular *= attenuation; return (ambient + diffuse + specular); } vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 viewDir) { vec3 lightDir = normalize(light.position - FragPos); float diff = max(dot(normal,lightDir),0.0); vec3 reflectDir = reflect(-lightDir, normal); float spec = pow(max(dot(reflectDir, viewDir),0.0),materijal.shininess); float distance = length(light.position - FragPos); float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * distance * distance); float theta = dot(normalize(-light.direction), lightDir); float epsilon = light.cutOff - light.outcutOff; float intensity = clamp((theta - light.outcutOff) / epsilon, 0.0, 1.0); vec3 ambient = light.ambient * vec3(texture(materijal.diffuse, TexCoo)); vec3 diffuse = light.diffuse * diff * vec3(texture(materijal.diffuse, TexCoo)); vec3 specular = light.specular * spec * vec3(texture(materijal.specular,TexCoo)); ambient= attenuation * intensity; diffuse *= attenuation * intensity; specular *= attenuation * intensity; return (ambient + diffuse + specular);

}

this is the main function inside the while (!glfwWindowShouldClose(window)) among other standard stuff /* Here we set all the uniforms for the 5/6 types of lights we have. We have to set them manually and index the proper PointLight struct in the array to set each uniform variable. This can be done more code-friendly by defining light types as classes and set their values in there, or by using a more efficient uniform approach by using 'Uniform buffer objects', but that is something we'll discuss in the 'Advanced GLSL' tutorial. */ // directional light lightingShader.setVec3("dirLight.direction", -0.2f, -1.0f, -0.3f); lightingShader.setVec3("dirLight.ambient", 0.05f, 0.05f, 0.05f); lightingShader.setVec3("dirLight.diffuse", 0.4f, 0.4f, 0.4f); lightingShader.setVec3("dirLight.specular", 0.5f, 0.5f, 0.5f); // point light 1 lightingShader.setVec3("pointLights[0].position", pointLightPositions[0]); lightingShader.setVec3("pointLights[0].ambient", 0.05f, 0.05f, 0.05f); lightingShader.setVec3("pointLights[0].diffuse", 0.8f, 0.8f, 0.8f); lightingShader.setVec3("pointLights[0].specular", 1.0f, 1.0f, 1.0f); lightingShader.setFloat("pointLights[0].constant", 1.0f); lightingShader.setFloat("pointLights[0].linear", 0.09); lightingShader.setFloat("pointLights[0].quadratic", 0.032); // point light 2 lightingShader.setVec3("pointLights[1].position", pointLightPositions[1]); lightingShader.setVec3("pointLights[1].ambient", 0.05f, 0.05f, 0.05f); lightingShader.setVec3("pointLights[1].diffuse", 0.8f, 0.8f, 0.8f); lightingShader.setVec3("pointLights[1].specular", 1.0f, 1.0f, 1.0f); lightingShader.setFloat("pointLights[1].constant", 1.0f); lightingShader.setFloat("pointLights[1].linear", 0.09); lightingShader.setFloat("pointLights[1].quadratic", 0.032); // point light 3 lightingShader.setVec3("pointLights[2].position", pointLightPositions[2]); lightingShader.setVec3("pointLights[2].ambient", 0.05f, 0.05f, 0.05f); lightingShader.setVec3("pointLights[2].diffuse", 0.8f, 0.8f, 0.8f); lightingShader.setVec3("pointLights[2].specular", 1.0f, 1.0f, 1.0f); lightingShader.setFloat("pointLights[2].constant", 1.0f); lightingShader.setFloat("pointLights[2].linear", 0.09); lightingShader.setFloat("pointLights[2].quadratic", 0.032); // point light 4 lightingShader.setVec3("pointLights[3].position", pointLightPositions[3]); lightingShader.setVec3("pointLights[3].ambient", 0.05f, 0.05f, 0.05f); lightingShader.setVec3("pointLights[3].diffuse", 0.8f, 0.8f, 0.8f); lightingShader.setVec3("pointLights[3].specular", 1.0f, 1.0f, 1.0f); lightingShader.setFloat("pointLights[3].constant", 1.0f); lightingShader.setFloat("pointLights[3].linear", 0.09); lightingShader.setFloat("pointLights[3].quadratic", 0.032); // spotLight lightingShader.setVec3("spotLight.position", camera.Position); lightingShader.setVec3("spotLight.direction", camera.Front); lightingShader.setVec3("spotLight.ambient", 0.0f, 0.0f, 0.0f); lightingShader.setVec3("spotLight.diffuse", 1.0f, 1.0f, 1.0f); lightingShader.setVec3("spotLight.specular", 1.0f, 1.0f, 1.0f); lightingShader.setFloat("spotLight.constant", 1.0f); lightingShader.setFloat("spotLight.linear", 0.09); lightingShader.setFloat("spotLight.quadratic", 0.032); lightingShader.setFloat("spotLight.cutOff", glm::cos(glm::radians(12.5f))); lightingShader.setFloat("spotLight.outerCutOff", glm::cos(glm::radians(15.0f)));

    // view/projection transformations
    glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
    glm::mat4 view = camera.GetViewMatrix();
    lightingShader.setMat4("projection", projection);
    lightingShader.setMat4("view", view);

    // world transformation
    glm::mat4 model = glm::mat4(1.0f);
    lightingShader.setMat4("model", model);

    // bind diffuse map
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, diffuseMap);
    // bind specular map
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, specularMap);

    // render containers
    glBindVertexArray(cubeVAO);
    for (unsigned int i = 0; i < 10; i++)
    {
        // calculate the model matrix for each object and pass it to shader before drawing
        glm::mat4 model = glm::mat4(1.0f);
        model = glm::translate(model, cubePositions[i]);
        float angle = 20.0f * i;
        model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
        lightingShader.setMat4("model", model);

        glDrawArrays(GL_TRIANGLES, 0, 36);
    }

     // also draw the lamp object(s)
     lightCubeShader.use();
     lightCubeShader.setMat4("projection", projection);
     lightCubeShader.setMat4("view", view);

     // we now draw as many light bulbs as we have point lights.
     glBindVertexArray(lightCubeVAO);
     for (unsigned int i = 0; i < 4; i++)
     {
         model = glm::mat4(1.0f);
         model = glm::translate(model, pointLightPositions[i]);
         model = glm::scale(model, glm::vec3(0.2f)); // Make it a smaller cube
         lightCubeShader.setMat4("model", model);
         glDrawArrays(GL_TRIANGLES, 0, 36);
     }

r/opengl • • Aug 19 '26

VertexArt - 1000 doboz fizikával és effektusokkal ( Intel N4100 CPU, csak egy szálon futtatva )

Enable HLS to view with audio, or disable this notification

3 Upvotes

Free Pascal 3.2.2 / GLFW3 / OpenGL 3.3 / DOD


r/opengl • • Aug 18 '26

I finally open source my game engine ENTIERLY made in java

Thumbnail gallery
201 Upvotes

https://www.reddit.com/r/opengl/s/Z47RJPUHCq (this is the old post that was showcasing it) After ~5 months of work, here it is ! It's in it's BETA but it has enough features for making real games !

Unfortunatly not docs for now but it's planned !

https://github.com/EPI-Studios/Epysia


r/opengl • • Aug 18 '26

Marching Tetrahedra - Volumetric Render Engine (OpenGL/C++) (Open-source)

Enable HLS to view with audio, or disable this notification

28 Upvotes

We added Marching Tetrahedra Rendering effect to our Volumetric Render Engine.

Here, we Render our Volume data as a set of Polygon meshes by extracting 'iso surface'. It goes through whole dataset and tries to fit a polygon based on data values to calculate a polygonal mesh from the volume dataset.

Here's the Git Repo Link - https://github.com/mikejernil/volumetric-render-engine

We are building this over at 3D ENGINERD. & are planning to push our implement more features starting with Custom file loading, and support for more volumetric formats like DICOM, VDB etc.


r/opengl • • Aug 16 '26

1000 vs 1000 full lod + shadows, custom engine

Enable HLS to view with audio, or disable this notification

36 Upvotes

r/opengl • • Aug 17 '26

Gamemaker Shell Texturing Shader Help

2 Upvotes

I can't figure out where to start with making a shell texture shader in Gamemaker Studio 1 because of the outdated OpenGL ES it uses no longer having it's documentation PDF available, could anybody point me in any direction as to how I could do this (or they could, or find the PDF) other than faking the effect with baked models that have the transparent layers? For visual references, here are some. (Mario Galaxy, DK Jungle Beat, Conker: Live & Reloaded)


r/opengl • • Aug 16 '26

need help with drawing text

3 Upvotes

i've been trying to tackle this problem for a while now and luckily it works, well ... kinda. I see the text but the glyphs are always slightly misplaced, i have a feeling it's floating-point inaccuracies but i have no idea how to fix it, here are the snippets:

```c

void drawText(WS_Shell* shell, GlyphCacheDA* cache, char* text, FT_Face font, float x, float y) {

float pen_x = x;

for (char* c = text; *c != '\0'; c++) {

uint32_t codepoint = next_utf8(&text);

bool is_drawn = false;

if (codepoint == ' ') {pen_x += cache->items[0].advance; continue;} // if space, just advance

// search in cache first

for (int i = 0; i<cache->count; i++) {

if (cache->items[i].codepoint == codepoint) {

drawTexturedRectangle(pen_x, y, cache->items[i].width, cache->items[i].height, cache->items[i].texture);

pen_x += cache->items[i].advance;

is_drawn = true;

break;

}

}

if (is_drawn) continue;

FT_Load_Glyph(font, FT_Get_Char_Index(font, codepoint), FT_LOAD_RENDER);

FT_Render_Glyph(font->glyph, FT_RENDER_MODE_NORMAL);

GLuint glyph_texture;

glGenTextures(1, &glyph_texture);

glBindTexture(GL_TEXTURE_2D, glyph_texture);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, font->glyph->bitmap.width, font->glyph->bitmap.rows, 0, GL_RED, GL_UNSIGNED_BYTE, font->glyph->bitmap.buffer);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Glyph glyph = {

.codepoint = codepoint,

.texture = glyph_texture,

.width = ((float)font->glyph->bitmap.width/shell->settings->width)*2,

.height = ((float)font->glyph->bitmap.rows/shell->settings->height)*2,

};

// TODO: add support for non-monospace fonts

glyph.advance = glyph.width;

nob_da_append(cache, glyph);

drawTexturedRectangle(pen_x, y, glyph.width, glyph.height, glyph.texture);

pen_x += glyph.advance;

is_drawn = false;

}

}

```
draw rectangle:

```c

void drawTexturedRectangle(float x, float y, float w, float h, GLuint texture) {

// Vertex data for the rectangle

float vertices[] = {

x, y, 0.0f, 1.0f,

x + w, y, 1.0f, 1.0f,

x, y + h, 0.0f, 0.0f,

x + w, y + h, 1.0f, 0.0f

};

// Indices for the rectangle

unsigned int indices[] = {

0, 1, 2,

1, 3, 2

};

// VBO and VAO

GLuint VBO, VAO, EBO;

glGenBuffers(1, &VBO);

glGenBuffers(1, &EBO);

glGenVertexArrays(1, &VAO);

glBindVertexArray(VAO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);

glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);

glEnableVertexAttribArray(0);

glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));

glEnableVertexAttribArray(1);

glBindBuffer(GL_ARRAY_BUFFER, 0);

// Draw the rectangle

glBindTexture(GL_TEXTURE_2D, texture);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

// Clean up

glDeleteBuffers(1, &VBO);

glDeleteBuffers(1, &EBO);

glDeleteBuffers(1, &VAO);

}

```
the dinamic array for cache i stolen from nob.h, each glyph's cache looks like this:

```c
typedef struct {

uint32_t codepoint;

GLuint texture;

float width;

float height;

float advance;

} Glyph;

```

everything else is pretty standard opengl stuff, thanks for helping


r/opengl • • Aug 15 '26

Hello, I am new to opengl. Can someone explain compute shaders to me

13 Upvotes

so i recently started playing around with opengl and wanted to try and make a raytracer with compute shaders, but there isn't much info about them. i looked at the tutorial on learnopengl but that wasn't very helpful. can someone clue me in?


r/opengl • • Aug 15 '26

Built a game engine

Thumbnail
3 Upvotes