Questions tagged [c]
C is a general-purpose computer programming language used for operating systems, libraries, games and other high performance work.
284 questions
0
votes
1
answer
115
views
Voxel Level Storage
I want to know some methods of storing the voxel data in a game like Infiniminer or Minecraft in a C++ program. What file types can do this easily? The voxel values will be big possibly a trillion by ...
0
votes
1
answer
133
views
What is the preferred memory to store game object into, Stack memory or Heap memory
In the context of game dev, what is the preferred memory to use to store structs like Entities or MapData which are large in size and have lifetimes lasting the entire game run-time.
For example here ...
0
votes
2
answers
160
views
Linked list in C
I only know C, no other language.
How do I use a linked list to store projectiles in sdl2?
My bullet currently has an sdl_image, has been queried and has the following properties:
...
0
votes
0
answers
45
views
Collision detection for a newbie [duplicate]
I am a freshman cs major with an interest in game dev. I know next to nothing and am very new to this so please bare with me.
TLDR; Should I use BSP for detection between moving and static objects as ...
0
votes
0
answers
70
views
How do I make my Software 3D Renderer slow down as soon as I change the screen resolution during runtime?
I'm writing a Software 3D Renderer in C many months after I first originally wrote it in Python. It is made using SDL2. My engine currently has depth shading, perspective correct texturing and some ...
0
votes
1
answer
132
views
OpenGL doesn't render even though all Objects and Data seems to be correctly set up
No shape seems to show up on screen even though I have meticulously verified everything.
The data set I use which is parsed by my code CORRECTLY(I checked that) to be loaded into a generic array ...
0
votes
0
answers
70
views
Invalid Pixel Offset Calculation Fix?
I am currently using a SDL_Texture *texture as a chunk in my world that is being Perlin noised onto to make terrain.
Using a 2d array of these I tile the plane. But ...
0
votes
0
answers
80
views
Is there more efficient method of terrain rendering in 2D plane than redrawing millions of SDL_FRect each frame
I want to render terrain efficently using perlin nosie and a lots of rects. Should I use rects or is there another way. Following is my implementation.
I use rect size = 1 which is not really ...
0
votes
1
answer
149
views
what is "viewport" mentioned in the raytracing in one weekend book?
I'm trying to make a simple raytracer following the raytracing in one weekend book, but I couldn't understand why is he using what is called a viewport, he define it as a virtual rectangle, why don't ...
0
votes
1
answer
113
views
Variable subdivision creating artifacts
I'm currently implementing a method for subdividing an icosahedron found here that isn't quite working as expected due to the artifacts created (and the way the triangles are oriented)
The problem ...
0
votes
0
answers
92
views
Need help to organize 2D AABB collision engine quad node structure
In short:
I'm writing my custom 2d collision engine in C and I've chosen to use quad nodes to optimize collision detection. My implementation defines 2 things: the quad node (Quad_s) and the elements (...
0
votes
1
answer
213
views
Why do I need two/three Vulkan pipelines for GUI presentation
For any that want to plumb Vulkan's complication I wish you well.
It's a badly documented software SDK and here's a perfect example of why it's never clear through context: I want to run an all-C ...
0
votes
0
answers
161
views
Why is my Gouraud Shading not working correctly?
I am trying to write a 3d Renderer in C using SDL and cgml but my shading seems to be not working correctly. When rendering the teapot I get seams and when I want to render a cube I get a bright white ...
0
votes
1
answer
120
views
Glyphs are not being drawn [opengl + freetype]
I've followed this source from learnopengl.com for text rendering. It seems fairly simple, and only required this much code:
...
0
votes
0
answers
69
views
How to re-design the graphics logic behind my game to preform better?
Recently, I have been working on a small "pet-project" of mine in C using the SDL library. I have noticed that without my render-calls, my project takes up 2% of the CPU and with the render-...
0
votes
0
answers
2k
views
Why is my RenderTexture y-flipped?
When drawing a very simple RenderTexture using Raylib, with the following POC code, the texture actually drawn is vertically inverted. Is that normal? If not, what ...
0
votes
1
answer
281
views
How can I handle voxels that require extra data in my octree?
I am using octrees as an efficient way to store voxel data in a voxel game. The details of my octree implementation can be found here, but in a nutshell, each node is 16 bits, and the most significant ...
1
vote
2
answers
243
views
Reduce entity-component system boilerplate
I'm attempting to create an entity-component system in C++.
However, I've run into an annoying issue where a component system function inherently involves a lot of ceremony and boilerplate. This is ...
1
vote
0
answers
77
views
Why opengl code in a lib doesn't renderer?
I am experimenting with opengl using c99 on windows and vs 2022 i tried to create an window using glfw in one project and put a function that supposed to generate a texture in another project that is ...
1
vote
0
answers
489
views
How to use SDL_RenderSetLogicalSize() properly in SDL2?
I want to handle different resolutions without altering any game objects. I tried using SDL_RenderSetLogicalSize() but I don't know how to implement it properly. ...
0
votes
1
answer
481
views
How to achieve no gaps between triangles in software renderer like in Quake?
I've heard alot that I need to use fixed-point math, top-left rule, etc. to eliminate gaps between triangles but the thing is how did Quake not have any gaps, did it? I've seen Quake's math file and ...
6
votes
3
answers
2k
views
How to install game with dependencies on Linux?
I am creating a game using C and some libraries. I wish to not require my users to download anything but the game as most games are self contained. What is the usual process for compiling and ...
0
votes
1
answer
137
views
How to add a slot to processing queue using a ring buffer with three pointers?
I am working on a farm game made in C. I am currently working on adding item processing, such as milling wheat into flour. Under the hood, I am using a ring buffer to handle the queues for processing. ...
0
votes
0
answers
146
views
Why are there gaps in my fibonacci sphere?
I recently took an interest in sphere topologies to find which one is the best. The most popular one seems to be the fibonacci sphere. So I went and did some research and found some C code online that ...
0
votes
1
answer
1k
views
How to set up view and model matrices for 3D rendering?
For various reasons I am building a very simple graphics engine. I have a pretty good 2D thing using plain SDL2 and C that essentially boils down to a single "putpixel" function. I can ...
1
vote
1
answer
126
views
Why is my texture moving?
I tried sampling equirectangular texture as a reflection. It simply does not work as intended. The texture is moving with my camera in a weird manner. Here is what I tried to do.
Fragment shader:
<...
0
votes
1
answer
142
views
Strange flashing cube bug in snake game
I'm trying to make a simple snake game in C and OpenGL, and I have this at the moment, which runs almost perfectly:
...
0
votes
2
answers
212
views
How can I make a reliable time-based object updating system?
So an object has a position, velocity, and is affected by gravity.
...
1
vote
0
answers
103
views
Are there OpenGL functions that are only available for specific platforms?
I want to load the OpenGL functions for my project myself.
Are there any specific functions besides wglGetSwapIntervalEXT that require me to query the spec for its availability? And if there are, ...
0
votes
0
answers
109
views
SDL2 Not destroying textures properly when updating text
Im implementing a series of textboxes in sdl2 ,however my program is not working correctly
-sdl is not destroying textures when the destroytexture function is callled resulting in a weird overlap of ...
1
vote
1
answer
1k
views
No vertex shader bound at draw?
I tried asking this on reddit but I didn't get any answers so I might as well try here
So I'm making a program to generate some terrain and it's not giving me the results I expected. It's drawing ...
25
votes
7
answers
4k
views
Consistent cross platform procedural generation
What techniques have people successfully used or can suggest to deal with a consistent cross platform math for procedural world generation? Also, if you have done this, what were the pros and cons of ...
1
vote
1
answer
518
views
Raycasting : computing x position of sprite on the screen
I am trying to create a raycasting engine using C and CSFML, I already have the walls and textures rendering done and right now I would like to be able to render sprites into the scene.
The difficulty ...
0
votes
1
answer
219
views
2
votes
1
answer
2k
views
SDL2 memory leak
I've been creating a 2D game in sdl2 in C and within my main game loop, I have found a section of code that causes a massive memory leak in my program, roughly leaking 100MB of memory per second.
The ...
2
votes
1
answer
6k
views
How to create editable SDL2 text input boxes?
Hi all, I'm working on an SDL2 project and I require multiple editable square textboxes as shown in the image above. Is there any way I can do this?
0
votes
1
answer
493
views
Rotation matrix for a model where the forward axis is not +X
I'm trying to convert a normalized unit vector, representing an entity heading, into a rotation matrix for rendering.
The problem is that I'm using an (apparently) unusual forward vector for my ...
1
vote
1
answer
558
views
Can't create Render Target with CreateDxgiSurfaceRenderTarget
I'm trying to create ID2D1RenderTarget to be used for writing text with DirectWrite. I tried two methods but can't get it working, both yield "The parameter is incorrect" error code.
In the ...
2
votes
1
answer
213
views
One global game loop vs multiple local game loops
What are the advantages of using multiple game loops instead of one?
Assume Level1, Level2, Level3. These levels may bring totally different problems and needs and they may also be completely separate,...
0
votes
1
answer
378
views
while(1) in separate threads. safe and efficient
In my TCP multithreaded server written in C, I have multiple threads with infinite loops checking for new inputs from thread safe queue and then doing their jobs. pseudocode:
...
0
votes
0
answers
437
views
State machine in C for SDL game
I want to create a state machine for menu in my SDL game. So this is my code without the SDL I just want to ask if this is a good way to create it.
here is a code:
...
0
votes
1
answer
129
views
Need help with optimizing loops scanning for enemies in tile based horizontal scroller
I'm looking for an optimization for my loops searching for enemies in a tile based horizonal scroller.
My enemy array is in a struct and I am looping through the array with 3 loops. First loop finds ...
1
vote
2
answers
630
views
Why would I want to set a minimal OpenGL version before creating the context?
Typical GLFW applications have these lines after glfwInit():
...
0
votes
0
answers
95
views
Best way to save screenshots in a game?
I'm making a game, and I'm adding a screenshots feature. Currently I save screenshot files to <Home Directory>/Pictures/MyGame/. However, I'm not sure if ...
0
votes
1
answer
144
views
Are there any serious advantages for C++ compared to C? [closed]
so I know a little bit about C (read like a few university level textbooks on it, I am not an experienced programmer or anything) and now I would like to learn the ropes of the Unreal engine to fidle ...
0
votes
2
answers
913
views
How can I handle input in C without halting the main loop?
I want my C program to update the console every second, and it was working fine until I tried to handle input. Now the program halts since it waits an input from the user. How can I do this?
...
0
votes
0
answers
85
views
Problem with bullet movement
I'm trying to draw "bullets" in my game, but I think something is wrong with velocity computation. Sometimes the "bullets" are going in the right way, but sometimes they won't. The ...
1
vote
0
answers
758
views
glReadPixels performance not improving with PBO
I'm currently using glReadPixels to read from the depth buffer to calculate where on the map the player is pointing, for the purpose of placing objects on the ground. I do this after rendering the ...
0
votes
2
answers
1k
views
Rotating camera in 3D without yawing diagonally
I'm programming a C raytracer. I'm having trouble getting the camera to rotate the way I intend.
I would like the camera to rotate by pressing keys:
F & H rotate left & right around the world'...
1
vote
1
answer
995
views
Polling events with SDL results in stuttering response when dealing with multiple objects
I'm new to SDL programming and I'm not quite sure I got how it handles events.
Given an instance like this defined in "game.c":
...