/r/opengl

Photograph via snooOG

News, information and discussion about OpenGL development.

/r/opengl

28,320 Subscribers

1

I want to better understand how shader read buffer objects.

I am familiar with modern opengl concepts and have been using it but still need to grip more on how shaders are fed buffer objects and how it works. What shall I do to have more clarity.

1 Comment
2024/11/14
12:59 UTC

2

Question about frame buffers and textures

I'm working on creating object picking by writing object id's to a second shader and outputting my initial output to a texture on a frame buffer.

My initial program is pretty simple and fixed. I have a total of 13 textures and a switch statement in my first shader.

All I did was add a second basic shader program that just has the screen coords as a buffer to draw the entire texture output from the first shader.

I crested my framebuffer, binding and unbinding when necessary. What I don't understand however is how textures work with the framebuffer.

Each program has it's own textures and own limits right? So if I assign my 13 textures to the first program, than the second one that uses the frame buffer just uses the default texture0 right? I'm just confused how the texture binding and activating works with multiple programs. Seems simple enough but I had feedback loops and all kinds of issues that I've fixed but now I'm just confused and feel like it's the texture part that's messed up. Am I misunderstanding how this all works?

Thanks in advance for any help!

2 Comments
2024/11/14
05:07 UTC

1

glfw and opengl suddenly doesn't work on my system!

Hello everyone hope y'all have a lovely day.

a couple of days later i was implementing omnidirectional shadow map on my engine, but for a strange error it showed a black screen which was doing some undefined behavior.

i tried to debug it but didn't reach to a solution, so i decided to make a new empty project and test to see where the problem start.

Finally made my project included glad and glfw and didn't do anything extraordinary, just cleared the color and for my shock my glfw window(which do nothing rather than having glClearColor(0.2f, 0.3f, 0.3f, 1.0f) color) is also black!

start debugging but nothing show to me, here is my simple program

opengl test.cpp

// opengl test.cpp : Defines the entry point for the application.

//

#include "opengl test.h"

#include <glad.h>

#include "glfw/include/GLFW/glfw3.h"

#include "Shader.h"

#define STB_IMAGE_IMPLEMENTATION

#include "stb_image.h"

int main()

{

// glfw: initialize and configure

// ------------------------------

glfwInit();

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);

glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// glfw window creation

// --------------------

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

if (window == NULL)

{

std::cout << "Failed to create GLFW window" << std::endl;

glfwTerminate();

return -1;

}

glfwMakeContextCurrent(window);

// glad: load all OpenGL function pointers

// ---------------------------------------

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))

{

std::cout << "Failed to initialize GLAD" << std::endl;

return -1;

}

// render loop

// -----------

while (!glfwWindowShouldClose(window))

{

// input

// -----

// render

// ------

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

glClear(GL_COLOR_BUFFER_BIT);

// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)

// -------------------------------------------------------------------------------

glfwSwapBuffers(window);

glfwPollEvents();

}

// glfw: terminate, clearing all previously allocated GLFW resources.

// ------------------------------------------------------------------

glfwTerminate();

return 0;

}

opengl test.h

// opengl test.h : Include file for standard system include files,

// or project specific include files.

#pragma once

#include <iostream>

Cmake

cmake_minimum_required (VERSION 3.28.3)

project(opengltest LANGUAGES C CXX)

set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)

set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)

set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

set (CMAKE_CXX_STANDARD 20)

include_directories(glad)

include_directories(glm)

add_subdirectory(glfw)

add_executable(opengltest "opengl test.cpp" "opengl test.h" "glad/glad.c" "Shader.cpp" "Shader.h" "stb_image.h")

target_link_libraries(opengltest glfw) #add assimp later

set_target_properties(

opengltest PROPERTIES

VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")

my application screenshot

renderdoc screen shot

appreciate any help.

1 Comment
2024/11/13
22:14 UTC

2

Are primitives within draw call ordered?

According to answer on stackoverflow I dig up, the rendering operations are supposed to be ordered unless incoherent memory access occurs (sampling and blending fall into that category according to OpenGL wiki).

I'm currently working on 2D engine where all tiles are already Y/Z sorted, so guaranteed order would allow me to batch most of draw calls into one

3 Comments
2024/11/13
21:27 UTC

0

Framebuffer works when using glBlitNamedFramebuffer but not when sampled in shader

Hi all, Ive posted previously about this problem but after doing more debugging its only got more bizzare. Im drawing my scene to an fbo with a colour and depth attachment and then rendering a quad to the scene sampling from the attached texture however all I see is a black screen. I have extensively tested the rectangle drawing code and it works with any other texture. moreover when using glBlitNamedFramebuffer it draws perfectly too the screen. using nvidea nsight and I can see the texture is being passed to the shader as well as another i was using for testing purposes.

im blending between the two samplers and only the test one appears at half brightness. The fbo attachment only returns black despite clearly being shown in nsight to be red

here nsight shows the scene been properly drawn to the fbo the desired contents of which are top right

heres my texture creation code used for both the fbo attachment and test texture

heres where i create the render texture

heres my blit code the texture in slot 1 being for debugging

heres the fragment shader

5 Comments
2024/11/13
20:45 UTC

0 Comments
2024/11/13
16:00 UTC

2

Framebuffers not drawing to screen

Hi all, been stumped by this for hours. I'm drawing my scene to a framebuffer then drawing a rectangle sampling from the attached texture. However I'm seeing a black screen. I've tried with other test textures and the problem does not seem to lie with the routine for drawing the rect to the screen. Upon inspection in nvidea Nsight (Renderdoc wouldn't run on my pc for some reason) all the objects are being correctly drawn to the FBO and the attached texture is being passed to the shader. All debugging I've tried shows it should work except it doesn't. Any help would be appreciated. I've attached a lot of the relevant source code however if any more is needed let me know.

FBO initialisation

texture initialisation

blit routine

framebuffer being drawn too

black screen being drawn despite sampler showing colour attachment

6 Comments
2024/11/12
21:36 UTC

9

Sharing my renderer progress

https://reddit.com/link/1gps9pp/video/h9l098hqqi0e1/player

What shall I do next I am open to suggestion; This is a little progress on my renderer using modern OpenGL. Last time it was two rectangles. Now they are cubes.

3 Comments
2024/11/12
18:54 UTC

2

How a voxel differ from cube rendered?

11 Comments
2024/11/12
17:02 UTC

4 Comments
2024/11/12
15:54 UTC

2

What must I learn to reverse engine the color balance function of Adobe Photoshop?

https://helpx.adobe.com/photoshop/using/applying-color-balance-adjustment.html

Here is the sumary of it. I want to do it with OpenGL, my input is bitmap with R, G, B, A and I want output like this too.

So how to calculate FragColor in Fragment Shader with R G B A of input and value of each seekbar, with or without peserve luminosity.

3 Comments
2024/11/12
11:39 UTC

3

Running shader from Shadertoy locally

I'd like to run the following shader that takes video as an input locally with a local video file as input:
https://www.shadertoy.com/view/MlS3DW

I tried to naively save the shader as a .frag file and run it using glslViewer but I get persistent syntax errors on

uniform samplerXX iChannel0..3;  

I believe this is some Shadertoy specific jargon that does not translate well and requires some adjusting or some wrapping with OpenGL (which I know nothing about).

A friend suggested I use max/msp to do so but I am running into problems with the .jxs file format which seems to be very different from .frag or whatever is displayed on Shadertoy itself.

  1. Is there a way to do this just with some OpenGL wrapper function? Can I run something like that smoothly on MacOS?

  2. If using Max, how do I get the shader into the right format? And do I have to be able to save the patch in a specific directory to be able to load the shader and video input? (Do I need to renew my license, basically).

Any suggestions/implementations/links would be very much appreciated.

Thanks!

2 Comments
2024/11/12
11:09 UTC

0

Rotate a cube and play sound at the same time in OpenGL?

Hi,

I'm wondering how you play sound file like WAV and rotate a cube in OpenGL at the same time in OpenGL,

I use SDL2 to play sound in OpenGL, how can you sync the rotation and sound in OpenGL?

2 Comments
2024/11/12
00:01 UTC

1

Black Textures after implementing omnidirectional shadow map

Hello guys, hope you have a lovely day.

so i tried implementing omnidirectional shadow map and all of a sudden i found that the whole screen was black, when i ran renderdoc i found that every single texture that is not depthMap texture(diffuse textures and my skybox texture) is black.

until now i have no idea why is that happening, here is my code .

appreciate any help

9 Comments
2024/11/11
23:19 UTC

3

Better triangle distribution on steep procedural terrain slopes?

Is it possible, given a height or vector displacement map sampled in a vertex shader, to compress stretched triangles post displacement on steeper parts of a terrain mesh? Typically steep slopes create very stretched triangles and as a result you get jagged peaks/edges. I thought about tessellation as well, but wouldn't the new triangles also be pretty stretched?

2 Comments
2024/11/11
09:41 UTC

0

I heard of io as memory and that open gl in a specification, so does that mean opengl is just a standard for how memory addresses are used to communicate with the gpu?

4 Comments
2024/11/11
05:39 UTC

1

How to optimize repeating values in vbo?

I have a vbo with face normals. Right now, I have to put the normal value four times, one for each vertex. How can I make this more efficient by only putting 1 value for 4 vertices?

8 Comments
2024/11/10
20:33 UTC

6

Render a big .OBJ file

Hi everyone,

I am part of a university project where I need to develop an app. My team has chosen Python as the programming language. The app will feature a 3D map, and when you click on an institutional building, the app will display details about that building.

I want the app to look very polished, and I’m particularly focused on rendering the 3D map, which I have exported as an .OBJ file from Blender. The file represents a real-life neighborhood.

However, the file is quite large, and libraries like PyOpenGL, Kivy, or PyGame don’t seem to handle the rendering effectively.

Can anyone suggest a way to render this large .OBJ file in Python?

21 Comments
2024/11/10
18:29 UTC

4

what is happening in my memory

I have always noticed with my opengl developement that there is a dip in memory usage after sometime when program starts even though all the allocations are being during initialization of gl context;

https://preview.redd.it/q1f3cn96o20e1.png?width=651&format=png&auto=webp&s=13cc1b8c820cb23c4cc610a5622474e9945e98e5

This trend I always notice during program runtime. And allocation are with 10MB offset +,- from 40MB during each run. What is happening behind the scene?

2 Comments
2024/11/10
13:03 UTC

23

Progress on my Multiplayer FPS in OpenGL

I just wanted to share some progress on my OpenGL Engine/Renderer/Game I've been working on, a couple weeks ago I was trying to figure if I wanted to make my game a single player FPS against AI or a multiplayer but after having a lot of fun playing STRATAT, I decided to make it multiplayer, heres a video of me and my friend doing a 1v1, The player models are beans right now just because I suck at animations but hopefully ill add proper people in later as well as ragdolls maybe, just wanted to share and get some feed back :)

https://www.youtube.com/watch?v=TNkH7IxkP3c

16 Comments
2024/11/10
01:04 UTC

3

omnidirectional shadow maps is black!

hello everyone hope u have a lovely day.

i have been working for two days now on implementing omnidirectional shadow map and every time i get this black screen

black screen without any information

i tried to debug it on render doc but it always crash and i still have no idea on what went wrong.

here is my code, really appreciate any help.

Edit:

My app

it actually worked but it is flickering and it returns back to black if i changed the window size.

2 Comments
2024/11/09
23:02 UTC

2

Texture isn't being displayed on OpenGL 1.1

I'm trying to draw a texture using the old school glBegin(), glTexCoord2f() and so on functions but although all the values seem to be correct I just get a white window output.

//Image loading
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &img->textureID);
glBindTexture(GL_TEXTURE_2D, img->textureID);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

int channels = 0;
unsigned char *data = stbi_load(imagePath, &img->width, &img->height, &channels, 0);
if(!data)
  return; // Actual fail code is more sophisticated, just as a placeholder

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
stbi_image_free(data);

glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);

// Draw code
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, img->textureID);

glBegin(GL_QUADS);

glTexCoord2f(0, 1);
glVertex2f(-1, 1);

glTexCoord2f(1, 1);
glVertex2f(1, 1);

glTexCoord2f(1, 0);
glVertex2f(1, -1);

glTexCoord2f(0, 0);
glVertex2f(-1, -1);

glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);

Now I don't think this code is wrong but as I only get a white window something has to be wrong. I really am just doing that. Create the image and draw it. Nothing more

5 Comments
2024/11/09
18:56 UTC

12

Was trying to optimize the memory usage of my block game, accidentally made the farlands (seriouslly)

0 Comments
2024/11/09
18:39 UTC

6

Sharing my progress in my project

https://reddit.com/link/1gne6wj/video/38930ad1nwzd1/player

I have modern OpenGL implementation implementing two rectangle in 3D space with axis plot for x,y,z; What feature shall I work on next? I am open to suggestion.

2 Comments
2024/11/09
16:45 UTC

Back To Top