/r/opengl

Photograph via snooOG

News, information and discussion about OpenGL development.

/r/opengl

26,019 Subscribers

1

[Help] Raycasting with sphere for object moving

Hi! I'm a bit of trouble with implementing raycasting for moving object. I think the problem is ray origin, but unfortunately I can't get it rigth

Currently, I use frame buffer to detect and get position of pressed vertex. And now I want to calculate intersection point between ray and this vertex, and move vertex center to new position

Current implementation:

glm::vec3 to_real_world_coords(glm::vec2 point) {
    auto& camera = stage::StageManager::Instance().Camera();

    glm::vec4 ndc_coords = glm::vec4(to_ndc({point.x, point.y, -1}), 1.0f);
    glm::vec4 eye_space = glm::inverse(camera->ProjectionMatrix()) * ndc_coords;
    return glm::inverse(camera->ViewMatrix()) * glm::vec4(eye_space.x, eye_space.y, -1, 0);
}
glm::vec3 origin = camera_->GetPosition(); // world position of camera
glm::vec3 direction = glm::normalize(math::to_real_world_coords(pos));

glm::vec3 vertex_position = model->GetTransformation() * glm::vec4(selected_vertex.position, 1.0f);

float t = glm::dot(vertex_position - origin, direction);
glm::vec3 new_position = glm::inverse(model->GetTransformation()) * glm::vec4(origin + direction * t, 1.0f);
0 Comments
2024/05/01
18:32 UTC

21

My own game engine/framework, in OpenGL, raw C

I make my own sort of OpenGL framework. I'm learning OpenGL seriously currently for a week. And I would like some feedback on the quality of the api (structures, functions, ...). Please give any constructive criticism you see fit. :)

Repo

17 Comments
2024/05/01
10:55 UTC

0

Blender Game Engine -- Film Grain

Hello, I'm completely new to GLSL and I was hoping to implement a nice looking film grain fx in my game. I have something that kind of works but it's a bit buggy. If anyone has any suggestions I'd love to hear it. I was hoping for something that I could control the size, strength (sharpness), color of the grain. Here is what I have from another code I found.

uniform sampler2D bgl_RenderedTexture;

float pi = 22.0/7.0;

uniform float frameTime;

out vec4 fragColor;

void main() {
  float amount = 0.02;

  vec2 texSize  = textureSize(bgl_RenderedTexture, 0).xy;
  vec2 texCoord = gl_FragCoord.xy / texSize;

  vec4 color = texture(bgl_RenderedTexture, texCoord);
  
  float randomIntensity =
  fract (10000 * sin((gl_FragCoord.x + gl_FragCoord.y * frameTime) * pi));
    
  amount *= randomIntensity;
  
  color.rgb += amount;

  fragColor = color;
}
2 Comments
2024/05/01
00:54 UTC

1

How to understand Union is Min , Intersection is Max ?

SDF math tools

Let's say we have some spheres in the scene , and P (photon) is an arbitrary point in the space .

if length(sphere[i].center - P) < sphere[i].radius , then point P is inside that sphere , i.e. collided with it

The following is how I use min and max to calculate union and intersection :

First of all , I made all these spheres having the same radius R .

Then , I looped all over through the spheres , and find out the min value of length(sphere[i].center - P) , i varying .

For this photon in the space , if the min distance it is away from all spheres is less than the standard radius R ,then there must be a sphere ( sphere[i] ) the photon is having collision with . Therefore , even if we have ten spheres out of range , as long as the eleventh is inside the range , we draw this pixel white , representing there is collision . Finally , we will have all the spheres drawn white , upon a black background . Black == Not Found

As for Intersection , I recorded the maximum value of length(sphere[i].center - P) , i varying .

If the max distance the photon is away from all spheres is less than R , then every one of spheres is inside the range . Among others , if there's one sphere where the photon is not on its surface neither inside of it , then the test will fail : the max distance is larger than R . 0 AND 1 equals 0 . We draw white only where the max distance is less than R , leaving all other areas black

My codes : Union, Intersect . Min & Max SDF (shadertoy.com)

Now I have a problem . If the radius R is not constant , being different for each sphere . Then how can I achieve Union and Intersection ? The only way I came up is to do inside-outside test for each sphere during the iteration , and then output a mask consisting of only 0 and 1 .

However , in this case . If we draw white for collision, then we expect using min to express intersection . Provided a 0 among 1s , the test fails , the output is 0.

But if we draw black for collision, then we expect using max to express intersection . Provided a 1 among 0s , the test fails , the output is 1.

Is the rule ( Union is min , intersection is max) only suitable for sdf , the actual distance a photon is away from spheres ? But how do you deal with different radius ?

3 Comments
2024/04/30
05:43 UTC

15

My progress with a little game engine/one day game!

4 Comments
2024/04/29
23:46 UTC

0

Need help extracting character sprites from "Date a Live: Rio Reincarnation" mod

Hello! I'm trying to create a mod for "Date a Live: Rio Reincarnation" and need help extracting the character sprites for further editing. Since its sprites are related to graphics and the mentioned viewer uses OpenGL and coding stuff, I came here for help. Here's my situation:

  • I've unpacked the original .pck game files and have some data, but it's in a format I don't understand.

https://preview.redd.it/p9aa6ptlehxc1.png?width=1050&format=png&auto=webp&s=1bd9a23866781fc954076dfc7d8ae11df665ea2e

Data within the .pck file

  • The website mpviewer.github.io/ renders the models correctly using .png and .mp files. I have these files, but I can't figure out how the .mp files control the sprite assembly.
  • I've reached out to the website creator without success.

My Goal: I want to use these sprites in a more flexible software like Live2D.

Can anyone help me with either of these?

  • Understanding the unpacked game file data so I can work with it directly.
  • Understanding the controls/functions of the Netlify app to get similar control in Live2D or another program.

Thanks so much for any advice!

1 Comment
2024/04/29
20:57 UTC

1

Particle System Tutorial, source code link in video description

0 Comments
2024/04/29
08:13 UTC

0

3D Object Databases with API support

I'm building a tool that requires 3D models from the web but I don't know where would be a good place to look. So far I've found Objaverse and it seems to have an API, but are there other free databases where I can find simple objects like "table" or "mug"? Scaled objects is preferred.

1 Comment
2024/04/29
00:30 UTC

10

Programming shaders on my own

I’ve been using OpenGL for 1 year now and although I can easily understand shader code, I still have a hard time implementing things on my own. I tried ShaderToy and although I understand and I can easily do trigonometry on a piece of paper,I don’t understand how sine cosine and all sorts of operations create fancy effects in shaders. Something still isn’t clicking for me. What could it be? It’s easy to understand lighting in shaders following the OpenGL tutorial… but coming up with something like that on my own? No way…

In short, how do you get good at programming shaders?

10 Comments
2024/04/28
21:30 UTC

1

Why must half the faces in a voxel have different uv coordinates when texturing?

0 Comments
2024/04/28
07:05 UTC

3

Debug callback is not getting invoked with glfw and gl crates

Hello, I have been trying to set up debug message callback in Rust with gl and glfw.

However the callback function is not getting invoked even though RenderDoc reports errors (I intentionally do not bind shader before draw call to check debugging). I also should mention that GetError function from gl crate doesn't return an error.

Could you please tell me, what I miss? I do not have extensive knowledge of these crates and Rust in general.

Here is how I initilalize my window

    let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();
    glfw.window_hint(glfw::WindowHint::ContextVersion(4,5));
    glfw.window_hint(glfw::WindowHint::OpenGlProfile(glfw::OpenGlProfileHint::Core)); 
    glfw.window_hint(glfw::WindowHint::ClientApi(glfw::ClientApiHint::OpenGl));  
    glfw.window_hint(glfw::WindowHint::OpenGlDebugContext(true));
    let (window, events) = glfw .create_window( WINDOW_WIDTH, WINDOW_HEIGHT, "Hello this  is window", glfw::WindowMode::Windowed, )
.expect("Failed to create GLFW window."); 
    let window = RefCell::new(window);
    window.borrow_mut().set_key_polling(true);
    window.borrow_mut().make_current();      

Here is my debug enabling; "have debug " is getting printed

 unsafe{
      let mut flags = 0;
      gl::GetIntegerv(gl::CONTEXT_FLAGS, &mut flags);
      if (flags as u32 & gl::CONTEXT_FLAG_DEBUG_BIT) != 0
      {
        println!("have debug");
        gl::Enable(gl::DEBUG_OUTPUT);
        gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS);
        gl::DebugMessageCallback(Some(gl_debug_log), ptr::null());
        gl::DebugMessageControl(gl::DONT_CARE, gl::DONT_CARE, gl::DONT_CARE, 0, ptr::null(), gl::TRUE);
      }
    }

Here is my callback function, "called debug" is never getting printed even though there is an error RenderDoc catches

extern "system" fn gl_debug_log(
  _: gl::types::GLenum,
  kind: gl::types::GLenum,
  _: gl::types::GLuint,
  _: gl::types::GLenum,
  _: gl::types::GLsizei,
  msg: *const gl::types::GLchar,
  _: *mut std::os::raw::c_void,
) {
  println!("called debug ");
  let msg = unsafe { CStr::from_ptr(msg).to_string_lossy() };
  match kind {
      gl::DEBUG_TYPE_ERROR | gl::DEBUG_TYPE_UNDEFINED_BEHAVIOR => {
          eprintln!("[OpenGL Error] {}", msg)
      },
      _ => eprintln!("[OpenGL ] {}", msg),
  }
}

RenderDoc error I want to catch

Versions of crates I am using

[dependencies]
gl = "0.14.0"
glam = "0.27.0"
glfw = "0.55.0"
2 Comments
2024/04/27
10:06 UTC

6

Trying to draw a rectangle with a certain color but is always blue no matter what

As the title suggests, I am trying to draw a rectangle but it fails to use the correct color that I am specifying. Also it fades to the left. Here is a picture:

Here is the vertex data being fed into my vertex and fragment shaders:

-0.5,   0.5,    0,      0.76,   0.13,   0.53,   1,      0,      1,
0.5,    0.5,    0,      0.76,   0.13,   0.53,   1,      1,      1,
0.5,    -0.5,   0,      0.76,   0.13,   0.53,   1,      1,      0,
-0.5,   -0.5,   0,      0.76,   0.13,   0.53,   1,      0,      0

The layout of my vertex data is as follows (first 3 are for position, 4 for color(RGBA), 2 for texture)

and finally here are my vertex and fragment shaders:

vertex:
#version 330 core

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec4 aColor;
layout (location = 2) in vec2 aTex;

out vec4 color;
out vec2 texCo;
void main()
{
    gl_Position = vec4(aPos, 1.0);
    color = aColor;
    texCo = aTex;
}

fragment:
#version 330 core
out vec4 FragColor;

in vec4 color;
in vec2 texCo;
uniform sampler2D tex;
uniform bool isTex;

void main()
{
    if(isTex){
        FragColor = texture(tex, texCo);
    }else{
        FragColor = color;
    }
}

https://preview.redd.it/4qxutzwrguwc1.png?width=1918&format=png&auto=webp&s=c960b79f6856d3b7657401dd0fa004a527fc4c8c

10 Comments
2024/04/26
15:49 UTC

2

Copying data from storage buffer to CPU

I am trying to copy data from a compute shader to the CPU. I have tried looking around for the solution but nothing has worked.

Here is where I create the compute shader SBO:

void OpenglControl::createSBO(unsigned int& shaderProgram, unsigned int& sbo, unsigned int size,unsigned int binding) {
    glUseProgram(shaderProgram);
    //SBO
    glGenBuffers(1, &sbo);
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, sbo);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding, sbo);
    glBufferData(GL_SHADER_STORAGE_BUFFER, size, NULL, GL_STREAM_READ);
}

Here is the compute shader SBO code:

struct Block {
    int type;
    int variant;
    int slopeVariant;
    int aboveExists;
    int belowExists;
    int upExists;
    int downExists;
    int leftExists;
    int rightExists;
};


struct Chunk {
    int chunkId;
    Block blocks[128][128][128];
};

layout(std430, binding = 1) buffer sbo {
    int numOfChunks;
    Chunk chunks[];
};

Here is where I try to get the data from the GPU:

void World::fetchChunkDataFromGPU(OpenglControl& openglControl) {
	glUseProgram(openglControl.getTerrainGenerationCoputeShaderProgram());
	glBindBuffer(GL_SHADER_STORAGE_BUFFER, openglControl.getChunkSBO());
	std::vector<int> data;
	glGetNamedBufferSubData(openglControl.getChunkSBO(), 0, ((sizeof(int32_t) * 9) * (128 * 128 * 128)) * 1, data.data());
	PRINT("DATA RECIVED FROM GPU");
}

Dispatch Code:

void World::generateWorld(OpenglControl& openglControl) {
this->chunks.push_back(Chunk(dt::vec3i(0, 0, 0)));
glUseProgram(openglControl.getTerrainGenerationComputeShaderProgram());
glBindBuffer(GL_UNIFORM_BUFFER, openglControl.getChunkSBO());
glBindBuffer(GL_UNIFORM_BUFFER, openglControl.getWorldSBO());
glDispatchCompute(1, 1, 1);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

this->fetchChunkDataFromGPU(openglControl);
}
14 Comments
2024/04/26
09:31 UTC

0

non-stable behavior when coloring object

Update 1: for missing function:

void setMaterial(float ambient[], float diffuse[], float specular[], float shiness)
{
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shiness);
}

also, I have setlight function

void setLight()
{
    const GLfloat leftLightDiffColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
    const GLfloat leftLightSpecColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
    const GLfloat leftLightAmbColor[] = {0.1f, 0.1f, 0.1f, 1.0f};
    const GLfloat leftLightPos[] = {10.0, 10.0, 10.0, 0.0};

    const GLfloat rightLightDiffColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
    const GLfloat rightLightSpecColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
    const GLfloat rightLightAmbColor[] = {0.1f, 0.1f, 0.1f, 1.0f};
    const GLfloat rightLightPos[] = {0.0, 0.0, 1.0, 0.0};

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_NORMALIZE);
    // glShadeModel(GL_SMOOTH);

    // set up right light
    glLightfv(GL_LIGHT0, GL_POSITION, rightLightPos);
    glLightfv(GL_LIGHT0, GL_AMBIENT, rightLightAmbColor);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, rightLightDiffColor);
    glLightfv(GL_LIGHT0, GL_SPECULAR, rightLightSpecColor);
    glEnable(GL_LIGHT0);

    // set up left light
    // glLightfv(GL_LIGHT1, GL_POSITION, leftLightPos);
    // glLightfv(GL_LIGHT1, GL_AMBIENT, leftLightAmbColor);
    // glLightfv(GL_LIGHT1, GL_DIFFUSE, leftLightDiffColor);
    // glLightfv(GL_LIGHT1, GL_SPECULAR, leftLightSpecColor);
    // // glEnable(GL_LIGHT1);
}

problem image: at initial the image here

https://preview.redd.it/t4ustehniswc1.png?width=1100&format=png&auto=webp&s=a91f9db45e5514a7f5cd7548414e5b67fddb6eb1

but turn out, when I press any key(w) in turn out actual as expected image as below

https://preview.redd.it/zp34mxiyiswc1.png?width=1100&format=png&auto=webp&s=3023f13e100619095b3b73423ac7903552dd24e0



Hi all, I got a a bug (or I think so). When I first running the program, the color always bolder as I expected. Then I press 'w' to change mode from wireframe to color, It turn out actual colors that I want. Here is the code for lighting.`

```

void myDisplay() {
//

	glViewport(0, 0, screenWidth, screenHeight);
	{

		//// Local ROTATE ALLOWED
		glPushMatrix();
		glRotatef(m_angleX, 1, 0, 0);
		glRotatef(m_angleZ, 0, 0, 1);

		{
			// Display the Tie bar (connecting object)
			drawTiebar();
			// Display 3 latch cylinder
			draw3latchCylinder();
			// Display 2 slider
			draw2slider();
			// Display Main CrossBar
			// drawMainbar();
		}
		glPopMatrix();
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////// END OF VIEW PORT /////////////////////////////////////////////////
		///
//
}
//
void drawTiebar()
{
	glPushMatrix();
	glTranslatef(0, fMainHeight + tieBar_height, 0);
	glTranslatef(sliderX_pos / 2, 0, sliderZ_pos / 2);
	glRotatef(m_angle, 0, 1, 0);
	glRotatef(180, 1, 0, 0);

	GLfloat ambient[] = {0.0, 0.0, 0.0, 1.0};
	GLfloat diffuse[] = {0.0, 1.0, 0.0, 1.0};
	GLfloat specular[] = {0.0, 0.0, 0.0, 1.0};
	GLfloat shininess = 100.0;
	setMaterial(ambient, diffuse, specular, shininess);
	if (e_colorMode == Colored)
	{
		tiebar.Draw();
	}
	else
	{
		tiebar.DrawWireframe();
	}
	glPopMatrix();
}

All help will be appreciated. Thanks

7 Comments
2024/04/26
02:47 UTC

10

2D coordinate systems with animated Graphs in OpenGL

  • Top-Left: Line
  • Top-Right: Bezier-Curve with one animated parameter
  • Bottom-Left: Bezier-Curve with two animated parameters
  • Bottom-Right: Multiples lines

https://reddit.com/link/1cd2aqg/video/fqeouokguowc1/player

Animated Bezier-Curves look pretty funky.

0 Comments
2024/04/25
20:47 UTC

1 Comment
2024/04/25
20:43 UTC

1

How to do spritesheet animations

I have a spritesheet that contains 11 32*32px sprites in one row. I have one quad that covers the entire viewport, going from (-1, -1) bottom left to (1, 1) top right. I've mapped the tex coords to this quad. Tex coords go from (0,0) to (1, 1) and bound the spritesheet to a texture. I have this line in the fragment shader to scale the sprites down back to their original size.

FragColor = texture(texture1, vec2(gl_FragCoord.x/352.0, gl_FragCoord.y/32.0));

This gives me an image such as this:

https://preview.redd.it/9a45v99yjnwc1.png?width=798&format=png&auto=webp&s=a9e82783766c97e53fe0e0e85f2e29de019c2423

I have also tried doing this in the vertex shader instead of the fragment shader:

vTexCoord = vec2(iTexCoord.x * 800.0/352.0, iTexCoord.y * 600.0/32.0 - .5);

800, 600 is my viewport width and height.

The - .5 at the end of the vTexCoord line was my attempt to move the sprites up the screen. What I get though is this:

https://preview.redd.it/rtnosd3fknwc1.png?width=799&format=png&auto=webp&s=0a5cdbb53ef619db6378bfc14e585a62c6afadd4

But for some reason the sprites are stretched. I think this is cos of the following code:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Is there a setting that neither clamp or repeat?

I want to draw one sprite from this sheet at a time, at a random position on the screen. How can I go about doing this?

I understand that in my vertex shader the 352 by 32 px spritesheet is stretched to 800 by 600 pixels and so I understand multiplying by 800/352, 600/32 will scale the texture back down.

What i don't understand is how to translate the sprites into different positions and mask certain sprites.

Is the vertex shader a better place to do this than the fragment shader?

I do not want to keep changing the vertex data or the texture so I have to do this in a shader.

code in main: https://pastebin.com/ig2XJKER

vertex shader: https://pastebin.com/4uGZcBRZ

fragment shader: https://pastebin.com/MNtNCK5C

9 Comments
2024/04/25
16:36 UTC

0

add saturation condition to a glsl shader

Hi, I have this vibrance shader, It has an srgb threshold which can be adjusted. But the shader affects all saturation levels. I would like to leave colors that have a saturation under 80% unaffected. And target the above 90% saturation pixels, with a smooth transition between them. From my understanding this shader already checks saturation but I don't know how this works. Any help would be appreciated 🙂

side note: I don't understand shaders, I just want to make this one adjustment.

//!PARAM vibr 
//!DESC Saturates/deSaturates 
//!TYPE float 
//!MINIMUM -1 
-0.3

//!HOOK MAIN 
//!BIND HOOKED 
//!DESC Vibrance

#define CoefLuma vec4(0.2126, 0.7152, 0.0722, 0) //sRGB, HDTV
float Thresh = 45.0/255.0; 
float w = 10.0/255.0;

vec4 hook() { 
vec4 c0 = HOOKED_texOff(0); 
float lum = (c0.r + c0.g + c0.b)/3.0;

float colorSat = max(max(c0.r, c0.g), c0.b) -min(min(c0.r, c0.g), c0.b); // >=0, 5 arithmetic 
vec3 sat = mix(vec3(dot(c0, CoefLuma)), c0.rgb, 1+vibr -colorSat*abs(vibr)); 
float delta = smoothstep( Thresh-w, Thresh+w, lum); 
c0.rgb = mix( sat, c0.rgb, delta); 
return c0;
}
0 Comments
2024/04/25
10:53 UTC

0

So I have been wanting to use Textures in OpenGL but they don't seem to be working

So I have been trying to use OpenGL in QT in order to make an application and I have come to need a custom text writer for my application, which I implemented but due to some reason, the textures don't seem to be loading in my project. Is there something particular to texture loading I'm missing I'm sure my vertex array and gl program is set correctly

Only the Writer and texture classes here are relevant, which are called in the renderer class

5 Comments
2024/04/25
10:48 UTC

3

A Thought on What to Offload to the GPU shaders

I admit I'm new to OpenGL and therefore lack experience. I'm able to draw things, rotate them, and follow other objects right now. I'm going through all the basics and learning the math behind the vectors and matrix transformations. As I was playing around and having a few hundred small triangles follow a player (just a dot in OpenGL), the thought came across my mind that instead of doing this all in the C++ code, I might be able to do this all in the shaders instead and get a massive improvement - right now, with my CPU, I can get about 50,000 triangles to follow the player dot with not too much performance degradation.

I don't know if I'm thinking about this incorrectly, but before I play around with the GPU shaders, is there some guidelines on what should and should not be tried in shaders vs the CPU?

18 Comments
2024/04/24
22:10 UTC

0

Model texture displaying as black

I am trying to follow along with learnopengl.com And I have made it to the model loading part. But even when I copy the scripts, it still displays as black. I've loaded assimp properly. There's nothing wrong with my model. I've made some modifications to the scripts, so if you wanna check them out here is the main.cpp: https://pastebin.com/HnWy4wjR Vertex shader: https://pastebin.com/zXXYr0rN Fragment shader: https://pastebin.com/Jw3Gy3Fj

2 Comments
2024/04/24
21:53 UTC

0

Compiling a shader causes a SIGSEGV on Android NDK OpenGL ES3

Hey everyone, I'm trying to set up a very simple renderer on Android with the Native Development Kit. I am able to call some basig gl Functions( like glClear() and such), but when trying to compile a shader, the app crashes.

The GLSurfaceView implementation in Kotlin:

class GraphicsView( context: Context ) : GLSurfaceView( context ) {

    private val renderer: Renderer

    init {
        setEGLContextClientVersion(3)
        renderer = Renderer( context )
        setRenderer(renderer)
    }
}

The vertex shader source code:

static const char triangle_vertex_shader[] =
        "#version 100\n"
        "void main()\n"
        "{\n"
        "    gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
        "}\0";

The native function which compiles the shader:

glViewport(0, 0, width, height);
glClearColor( 0.1f, 0.3f, 0.1f, 1.0f );
unsigned int    _vert_shdr = 0;
_vert_shdr = glCreateShader( GL_VERTEX_SHADER );
glShaderSource( _vert_shdr, 1, triangle_vertex_shader, NULL );

I have omitted some code in order to keep the post clean, but if you think anything else is relevant, I'll add it. (everything else is pretty basic, I made sure to follow whatever resources I found online)

If anyone has any advice, I'd be grateful! My plan is to import my bigger OpenGL renderer from desktop GL to mobile.

4 Comments
2024/04/24
18:41 UTC

1

Issues with implementing SSAO

Hi, I'm having issues with my screen space ambient occlusion implementation. I was trying to follow this tutorial from learnopengl. My issue is that every fragment that has a lower z frag pos than the camera's z position is like "inverted" as seen in the attached screenshot.
I honestly can't claim to fully understand how the actual math for SSAO works which is also kind of why im lost here while debugging. Here is my GLSL code for the SSAO calculations: https://pastebin.com/CD4mcTeN the projection uniform is the perspective matrix from the camera (which i am pretty sure is the correct thing to be using), samples[] is 64 random positions in a hemisphere to sample from and texNoise is a 4x4 texture of random vec3s.
I can happily provide additional source code or screenshots if you think my issue could be somewhere else. Any insight would be greatly appreciated.

https://preview.redd.it/zw9oap4xngwc1.png?width=1916&format=png&auto=webp&s=4d5a957b548e4bec94795a7955f21aaa48d97950

4 Comments
2024/04/24
17:20 UTC

1

Transparent object rendering problem

Hi everyone!

I have a scene with transparent and non-transparent cubes. For the non-transparent ones I implemented several lightning options, which work great. However I can not find a solution to my problem shown in the following video.

I want OpenGL to only render the first visible face of any transparent object, while still rendering non transparent objects behind them. Now instead the amount of rendered transparent faces change as I rotate and move the camera. As you can see when I move the camera on the left side many faces of the transparent cube are rendered, while on the right side of the screen only the front face is rendered, which is what I want to achive. I do not even know the reason why transparent objects are rendered like this so even an explanation alone will be much appreciated.

In the video only ambient lightning is applied to the transparent cubes, so this effect is not caused by lightning.

Thanks for your help!

https://reddit.com/link/1cc22hu/video/y0qwf2oebgwc1/player

4 Comments
2024/04/24
16:07 UTC

0

Documentation for GLFW.

Hey, is there another documentation for all the GLFW functions and window hints other than the official documentation. Are there any similar to docs.gl where everything is in a nice organized table.

1 Comment
2024/04/24
14:04 UTC

1

Help me understand OpenGL

Hello.

I’ve started learning OpenGL and I’ve managed to render a triangle.

I have added a button in my spp that when pressed I add another triangle.

However, my scene is now flickering.

I’ve heard a few different things regarding this, such as:

  • I should build the triangle every time my render function is called
  • I cannot dynamically create new triangles while rendering
  • I have to create all my triangles during initialization
  • Etc

Can anyone share some relevant information with me?

30 Comments
2024/04/24
07:43 UTC

0

Frames being delayed by other applications

Hello, I'm currently running into an issue where another application is causing frame delay on my opengl app that is then causing screen tearing in it.

If I disable v sync, the screen tearing disappears, but that would not be ideal solution. Is there another solution to fix it?

5 Comments
2024/04/22
18:05 UTC

Back To Top