Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 588c229

Browse files
committed
update
1 parent 1a4380d commit 588c229

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

cncvis/api.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ ZBuffer *globalFramebuffer = NULL;
1818
ucncAssembly *globalScene = NULL;
1919
ucncCamera *globalCamera = NULL;
2020

21-
int framebufferWidth = (int)globalFramebuffer->xsize;
22-
int framebufferHeight = (int)globalFramebuffer->ysize;
23-
2421
ucncLight **globalLights = NULL;
2522
int globalLightCount = 0;
2623

@@ -104,14 +101,24 @@ void ucncSetAllAssembliesToHome(ucncAssembly *assembly) {
104101
}
105102
}
106103

107-
// Set the dimensions of the TinyGL Z-buffer
108-
void ucncSetZBufferDimensions(int width, int height) {
104+
// Set the dimensions of the TinyGL Z-buffer and return width/height
105+
void ucncSetZBufferDimensions(int width, int height, int *outFramebufferWidth, int *outFramebufferHeight) {
106+
109107
if (globalFramebuffer) {
110108
ZB_close(globalFramebuffer);
111109
}
112110
globalFramebuffer = ZB_open(width, height, ZB_MODE_RGBA, 0);
113111
if (!globalFramebuffer) {
114112
fprintf(stderr, "Failed to initialize Z-buffer with dimensions %d x %d.\n", width, height);
113+
return;
114+
}
115+
116+
// Set the output width and height using the provided pointers
117+
if (outFramebufferWidth) {
118+
*outFramebufferWidth = globalFramebuffer->xsize;
119+
}
120+
if (outFramebufferHeight) {
121+
*outFramebufferHeight = globalFramebuffer->ysize;
115122
}
116123
}
117124

cncvis/api.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
extern ucncLight **globalLights;
1010
extern int globalLightCount;
1111

12-
extern int framebufferWidth;
13-
extern int framebufferHeight;
14-
1512
// Global frame buffer and scene declaration
1613
extern ZBuffer *globalFramebuffer;
1714
extern ucncAssembly *globalScene;
@@ -23,7 +20,7 @@ void ucncSetAllAssembliesToHome(ucncAssembly *assembly);
2320
void ucncUpdateMotion(ucncAssembly *assembly, float value);
2421

2522
// Z-buffer handling
26-
void ucncSetZBufferDimensions(int width, int height);
23+
void ucncSetZBufferDimensions(int width, int height, int *outFramebufferWidth, int *outFramebufferHeight);
2724
const float* ucncGetZBufferOutput(void);
2825
void ucncFrameReady(ZBuffer *framebuffer);
2926

main/src/main.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ static uint8_t *cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 32, LV_DRAW
5757
/**********************
5858
* GLOBAL VARIABLES
5959
**********************/
60-
extern ZBuffer *globalFramebuffer; // Make sure it matches your `api.h`
60+
extern ZBuffer *globalFramebuffer;
6161
extern ucncAssembly *globalScene;
6262

63+
int framebufferWidth;
64+
int framebufferHeight;
65+
6366
/*********************
6467
* GLOBAL FUNCTIONS
6568
*********************/
@@ -125,9 +128,10 @@ int main(int argc, char **argv) {
125128
// Initialize the TinyGL framebuffer (through the CNC API)
126129

127130
printf("Setting Z-buffer dimensions...\n");
128-
ucncSetZBufferDimensions(CANVAS_WIDTH-16, CANVAS_HEIGHT-16);
131+
ucncSetZBufferDimensions(CANVAS_WIDTH-16, CANVAS_HEIGHT-16, &framebufferWidth, &framebufferHeight);
129132

130-
printf("Z-buffer initialized: %d x %d\n", globalFramebuffer->xsize, globalFramebuffer->ysize);
133+
// Now framebufferWidth and framebufferHeight will be updated to the correct values
134+
printf("Framebuffer Size: %d x %d\n", framebufferWidth, framebufferHeight);
131135

132136
// Initialize the CNC scene (you could load an initial configuration here)
133137
printf("Loading CNC scene...\n");

0 commit comments

Comments
 (0)