Skip to content

Commit 4aef7e7

Browse files
fix compilation and using #prama region now
1 parent 91fc807 commit 4aef7e7

File tree

8 files changed

+538
-500
lines changed

8 files changed

+538
-500
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.dll
2+
.kdev4/
3+
LICENSE.zlib.txt
4+
.vscode/
5+
1
6+
2
7+
3
8+
4
9+
curves.kdev4
10+
casteljau

Makefile

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
CFLAGS = -Wall -Wextra -mtune=native `sdl2-config --cflags`
1+
CFLAGS = -Wall -Wextra -mtune=native -no-pie `sdl2-config --cflags`
22
LDFLAGS = `sdl2-config --libs` -lSDL2_image -lm -lSDL2_gfx
33

44
.SUFFIXES:
55
.SUFFIXES: .c .o
66

7-
srcdir =src/
8-
TARGETS = casteljau 1 2 3 4
7+
srcdir = src/
8+
TARGETS = casteljau 1 2 3
99

1010
.PHONY: all
1111
all: $(TARGETS)
@@ -22,9 +22,6 @@ casteljau: $(srcdir)helper.c $(srcdir)4.c
2222
3: $(srcdir)helper.c $(srcdir)3.c
2323
$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
2424

25-
4: $(srcdir)helper.c $(srcdir)4.c
26-
$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
27-
2825
.PHONY: clean
2926
clean:
3027
@rm $(TARGETS) 2>/dev/null || true

src/1.c

+123-116
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//BEGIN HEAD
2-
//BEGIN DESCRIPTION
1+
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
2+
#pragma region HEAD
3+
#pragma region DESCRIPTION
34

45
/* light SDL2 template
56
* DeCasteljau Subdivision
@@ -10,173 +11,179 @@
1011
* connect 4 points with 3 lines
1112
*
1213
*/
13-
//END DESCRIPTION
14+
#pragma endregion DESCRIPTION
1415

15-
//BEGIN INCLUDES
16+
#pragma region INCLUDES
1617
//system headers
1718
#include <math.h>
1819
//local headers
1920
#include "helper.h"
2021
#include <SDL2/SDL2_gfxPrimitives.h>
2122

22-
//END INCLUDES
23+
#pragma endregion INCLUDES
2324

24-
//BEGIN CPP DEFINITIONS
25-
#define WHITE 255,255,255,255
26-
#define BLACK 0,0,0,255
27-
#define RED 255,0,0,255
25+
#pragma region CPP DEFINITIONS
26+
#define WHITE 255, 255, 255, 255
27+
#define BLACK 0, 0, 0, 255
28+
#define RED 255, 0, 0, 255
2829
#define WW 550
29-
#define WH (WW/16)*12
30+
#define WH (WW / 16) * 12
3031
#define POINTS 4
31-
//END CPP DEFINITIONS
32+
#pragma endregion CPP DEFINITIONS
3233

33-
//BEGIN DATASTRUCTURES
34+
#pragma region DATASTRUCTURES
3435
SDL_Point points[POINTS];
3536

36-
//END DATASTRUCTURES
37+
#pragma endregion DATASTRUCTURES
3738

38-
//BEGIN GLOBALS
39-
int ww=WW;
40-
int wh=WH;
39+
#pragma region GLOBALS
40+
int ww = WW;
41+
int wh = WH;
4142

42-
//BEGIN VISIBLES
43-
SDL_Surface *temp_surface = NULL;
43+
#pragma region VISIBLES
44+
SDL_Surface *temp_surface = NULL;
4445

45-
SDL_Texture *logo = NULL;
46-
SDL_Rect logo_dst;
47-
//END VISIBLES
46+
SDL_Texture *logo = NULL;
47+
SDL_Rect logo_dst;
48+
#pragma endregion VISIBLES
4849

49-
SDL_Point mouse;
50+
SDL_Point mouse;
5051

51-
//END GLOBALS
52+
#pragma endregion GLOBALS
5253

53-
//BEGIN FUNCTION PROTOTYPES
54-
void assets_in (void);
55-
void assets_out (void);
56-
//END FUNCTION PROTOTYPES
54+
#pragma region FUNCTION PROTOTYPES
55+
void assets_in(void);
56+
void assets_out(void);
57+
#pragma endregion FUNCTION PROTOTYPES
58+
#pragma endregion HEAD
5759

58-
//END HEAD
59-
60-
//BEGIN MAIN FUNCTION
60+
#pragma region MAIN FUNCTION
6161
int main(int argc, char *argv[])
6262
{
6363

64-
(void)argc;
65-
(void)argv;
66-
67-
//BEGIN INIT
68-
init();
69-
assets_in();
70-
71-
//BEGIN WINDOW
72-
SDL_SetWindowPosition(Window,0,0);
73-
SDL_SetWindowSize(Window,ww,wh);
74-
SDL_SetWindowTitle(Window, "SDL2 Template");
75-
SDL_ShowWindow(Window);
76-
//END WINDOW
77-
78-
int r=255,g=0,b=0,a=255;
79-
points[0].x=40;
80-
points[0].y=WH/2;
81-
82-
points[1].x=142;
83-
points[1].y=55;
84-
points[2].x=372;
85-
points[2].y=334;
86-
points[3].x=WW-40;
87-
points[3].y=160;
88-
89-
SDL_Event event;
90-
int running = 1;
91-
//END INIT
92-
93-
//BEGIN MAIN LOOP
94-
while(running){
95-
96-
//BEGIN EVENT LOOP
97-
SDL_GetMouseState(&mouse.x, &mouse.y);
98-
while(SDL_PollEvent(&event)){
99-
if(event.type == SDL_QUIT){
100-
running =0;
101-
}
102-
if(event.type == SDL_MOUSEMOTION){
103-
SDL_Log("x:%d y:%d",mouse.x, mouse.y);
104-
}
105-
if(event.type == SDL_MOUSEBUTTONDOWN){
106-
if(event.button.button == SDL_BUTTON_RIGHT){
107-
;
64+
(void)argc;
65+
(void)argv;
66+
67+
#pragma region INIT
68+
init();
69+
assets_in();
70+
71+
#pragma region WINDOW
72+
SDL_SetWindowPosition(Window, 0, 0);
73+
SDL_SetWindowSize(Window, ww, wh);
74+
SDL_SetWindowTitle(Window, "SDL2 Template");
75+
SDL_ShowWindow(Window);
76+
#pragma endregion WINDOW
77+
78+
int r = 255, g = 0, b = 0, a = 255;
79+
points[0].x = 40;
80+
points[0].y = WH / 2;
81+
82+
points[1].x = 142;
83+
points[1].y = 55;
84+
points[2].x = 372;
85+
points[2].y = 334;
86+
points[3].x = WW - 40;
87+
points[3].y = 160;
88+
89+
SDL_Event event;
90+
int running = 1;
91+
#pragma endregion INIT
92+
93+
#pragma region MAIN LOOP
94+
while (running)
95+
{
96+
97+
#pragma region EVENT LOOP
98+
SDL_GetMouseState(&mouse.x, &mouse.y);
99+
while (SDL_PollEvent(&event))
100+
{
101+
if (event.type == SDL_QUIT)
102+
{
103+
running = 0;
108104
}
109-
if(event.button.button == SDL_BUTTON_MIDDLE){
110-
;
105+
if (event.type == SDL_MOUSEMOTION)
106+
{
107+
SDL_Log("x:%d y:%d", mouse.x, mouse.y);
111108
}
112-
if(event.button.button==SDL_BUTTON_LEFT){
113-
;
109+
if (event.type == SDL_MOUSEBUTTONDOWN)
110+
{
111+
if (event.button.button == SDL_BUTTON_RIGHT)
112+
{
113+
;
114+
}
115+
if (event.button.button == SDL_BUTTON_MIDDLE)
116+
{
117+
;
118+
}
119+
if (event.button.button == SDL_BUTTON_LEFT)
120+
{
121+
;
122+
}
114123
}
115-
}
116-
if(event.type == SDL_KEYDOWN ){
117-
switch(event.key.keysym.sym ){
124+
if (event.type == SDL_KEYDOWN)
125+
{
126+
switch (event.key.keysym.sym)
127+
{
118128
case SDLK_ESCAPE:
119-
running =0;
129+
running = 0;
120130
break;
121131

122132
case SDLK_r:
123133
case SDLK_BACKSPACE:
124134
break;
125135

126-
case SDLK_p:
136+
case SDLK_p:
127137
case SDLK_SPACE:
128138
break;
129-
139+
130140
default:
131141
break;
142+
}
132143
}
133144
}
134-
}
135-
//END EVENT LOOP
136-
//BEGIN RENDERING
137-
SDL_SetRenderDrawColor(Renderer, WHITE);
138-
SDL_RenderClear(Renderer);
139-
140-
SDL_RenderCopy(Renderer, logo, NULL, &logo_dst);
141-
142-
for ( int i=0; i<POINTS; i++){
143-
aacircleRGBA(Renderer, points[i].x, points[i].y, 4, r,g,b,a);
144-
if (i<POINTS-1)
145-
aalineRGBA(Renderer, points[i].x, points[i].y,
146-
points[i+1].x, points[i+1].y, r,g,b,a);
147-
}
148-
149-
150-
151-
SDL_RenderPresent(Renderer);
152-
//END RENDERING
153-
}
154-
//END MAIN LOOP
145+
#pragma endregion EVENT LOOP
146+
#pragma region RENDERING
147+
SDL_SetRenderDrawColor(Renderer, WHITE);
148+
SDL_RenderClear(Renderer);
149+
150+
SDL_RenderCopy(Renderer, logo, NULL, &logo_dst);
151+
152+
for (int i = 0; i < POINTS; i++)
153+
{
154+
aacircleRGBA(Renderer, points[i].x, points[i].y, 4, r, g, b, a);
155+
if (i < POINTS - 1)
156+
aalineRGBA(Renderer, points[i].x, points[i].y,
157+
points[i + 1].x, points[i + 1].y, r, g, b, a);
158+
}
155159

156-
assets_out();
157-
exit_();
158-
return EXIT_SUCCESS;
160+
SDL_RenderPresent(Renderer);
161+
#pragma endregion RENDERING
162+
}
163+
#pragma endregion MAIN LOOP
159164

165+
assets_out();
166+
exit_();
167+
return EXIT_SUCCESS;
160168
}
161-
//END MAIN FUNCTION
169+
#pragma endregion MAIN FUNCTION
162170

163-
//BEGIN FUNCTIONS
171+
#pragma region FUNCTIONS
164172
void assets_in(void)
165173
{
166174

167-
//BEGIN LOGO
175+
#pragma region LOGO
168176
temp_surface = IMG_Load("./assets/gfx/logo.png");
169177
logo = SDL_CreateTextureFromSurface(Renderer, temp_surface);
170178
SDL_QueryTexture(logo, NULL, NULL, &logo_dst.w, &logo_dst.h);
171-
logo_dst.x=(ww/2)-(logo_dst.w/2);
172-
logo_dst.y=(wh/2)-(logo_dst.h/2);
173-
//END LOGO
174-
179+
logo_dst.x = (ww / 2) - (logo_dst.w / 2);
180+
logo_dst.y = (wh / 2) - (logo_dst.h / 2);
181+
#pragma endregion LOGO
175182
}
176183

177184
void assets_out(void)
178185
{
179186
SDL_DestroyTexture(logo);
180187
}
181188

182-
//END FUNCTIONS
189+
#pragma endregion FUNCTIONS

0 commit comments

Comments
 (0)