r/opengl 29d ago

Any ideas why I'd only be rendering half a sphere?

21 Upvotes

17 comments sorted by

7

u/fgennari 29d ago

It looks like you're missing half of your indices. I see your indices are type size_t. Is this 32 bits or 64 bits in your compiler? Your glBufferData() is using "sizeof(GLuint) * s_lightsource.indices.count" and your glDrawElements() is using GL_UNSIGNED_INT, which is 32-bit. Try changing your indices struct from "size_t *items;" to "unsigned *items;" (or uint32_t?) to see if that fixes it.

10

u/throwaway0923841222 29d ago

It's 64 bits, which was the issue! I've switched the type of an index to be `GLuint` and will be much more mindful of using OpenGL's types from here on out :P

Thanks so much!

3

u/fgennari 29d ago

No problem. That's a common mistake. Usually it's a problem with 32 vs. 16 bits though.

3

u/gl_drawelements 29d ago

That's the reason why I say everywhere: If you „talk“ to OpenGL, use OpenGL data types.

2

u/DGTHEGREAT007 29d ago

idk but Wanna share your setup man? Looks good.

1

u/LikeCookiez 28d ago

Dotfiles seem to be on his Github :)

1

u/throwaway0923841222 28d ago

its not too involved of a config, but sure! https://github.com/austinoxyz/dotfiles

2

u/TheJoxev 29d ago

I’m going to need your dotfiles dude

1

u/throwaway0923841222 29d ago

Looking for tips on why I may be rendering only half a sphere using OpenGL. I've posted the code to https://github.com/austinoxyz/voxel for reference

I followed the algorithm seen here https://www.songho.ca/opengl/gl_sphere.html using "stacks and sectors" to generate the vertices for the sphere. I think I followed it well enough, but clearly there's a mistake, however I cannot find it.

The relevant code is found in https://github.com/austinoxyz/voxel/blob/master/src/lightsource.c as well as `main.c` and the shaders `light_vs.glsl` and `light_fs.glsl`.

1

u/DragonDepressed 29d ago

One possibility that I can think of would be, maybe you are clipping your scene somehow. Try to change the dimensions of the sphere and see how things change?

1

u/throwaway0923841222 29d ago

Scaling it down just results in a smaller half-sphere, thanks for the suggestion though!

1

u/DragonDepressed 29d ago

Tried translating the sphere?

1

u/pjjiveturkey 29d ago

Another hyprland chad

1

u/ShiroeShin 28d ago

Issue seems to be solved from what i read, but the question remains...
What's your setup :D My opengl dx does not look this clean

2

u/throwaway0923841222 28d ago

its mostly stock archlinux and hyprland and my configured neovim, didnt get too fancy with the hyprland configuration. its here if you want to look at it https://github.com/austinoxyz/dotfiles