@@ -264,6 +264,10 @@ void gl_camera_zoom(gl_camera_t *camera,
264
264
* GL-PRIMITIVES
265
265
*****************************************************************************/
266
266
267
+ void gl_triangle_setup (gl_entity_t * entity , GLfloat pos [3 ]);
268
+ void gl_triangle_cleanup (const gl_entity_t * entity );
269
+ void gl_triangle_draw (const gl_entity_t * entity , const gl_camera_t * camera );
270
+
267
271
void gl_cube_setup (gl_entity_t * entity , GLfloat pos [3 ]);
268
272
void gl_cube_cleanup (const gl_entity_t * entity );
269
273
void gl_cube_draw (const gl_entity_t * entity , const gl_camera_t * camera );
@@ -374,39 +378,6 @@ void gui_setup(gui_t *gui);
374
378
void gui_reset (gui_t * gui );
375
379
void gui_loop (gui_t * gui );
376
380
377
- /******************************************************************************
378
- * IMSHOW
379
- *****************************************************************************/
380
-
381
- // typedef struct imshow_t {
382
- // SDL_Window *window;
383
- // SDL_Renderer *renderer;
384
-
385
- // char *window_title;
386
- // int window_width;
387
- // int window_height;
388
- // int loop;
389
-
390
- // SDL_Surface *image_surface;
391
-
392
- // gl_camera_t camera;
393
- // GLfloat movement_speed;
394
- // GLfloat mouse_sensitivity;
395
-
396
- // int left_click;
397
- // int right_click;
398
- // int last_cursor_set;
399
- // float last_cursor_x;
400
- // float last_cursor_y;
401
- // } imshow_t;
402
-
403
- // void imshow_window_callback(imshow_t *imshow, const SDL_Event event);
404
- // void imshow_keyboard_callback(imshow_t *imshow, const SDL_Event event);
405
- // void imshow_event_handler(imshow_t *gui);
406
- // void imshow_setup(imshow_t *imshow, const char *fp);
407
- // void imshow_reset(imshow_t *imshow);
408
- // void imshow_loop(imshow_t *imshow);
409
-
410
381
#endif // GUI_H
411
382
412
383
#ifdef GUI_IMPLEMENTATION
@@ -2255,11 +2226,22 @@ void gui_loop(gui_t *gui) {
2255
2226
glClear (GL_COLOR_BUFFER_BIT );
2256
2227
2257
2228
gl_cube_draw (& cube , & gui -> camera );
2258
- gl_camera_frame_draw (& cf , & gui -> camera );
2229
+ // gl_camera_frame_draw(&cf, &gui->camera);
2259
2230
// gl_axis_frame_draw(&frame, &gui->camera);
2260
2231
gl_grid_draw (& grid , & gui -> camera );
2261
2232
// gl_model_draw(model, &gui->camera);
2262
2233
2234
+ glBegin (GL_QUADS );
2235
+ glColor3d (1 , 0 , 0 );
2236
+ glVertex3f (-1 , -1 , -10 );
2237
+ glColor3d (1 , 1 , 0 );
2238
+ glVertex3f (1 , -1 , -10 );
2239
+ glColor3d (1 , 1 , 1 );
2240
+ glVertex3f (1 , 1 , -10 );
2241
+ glColor3d (0 , 1 , 1 );
2242
+ glVertex3f (-1 , 1 , -10 );
2243
+ glEnd ();
2244
+
2263
2245
// Update
2264
2246
glfwSwapBuffers (gui -> window );
2265
2247
glfwSetWindowAspectRatio (gui -> window , 16 , 9 );
@@ -2274,201 +2256,6 @@ void gui_loop(gui_t *gui) {
2274
2256
glfwTerminate ();
2275
2257
}
2276
2258
2277
- /******************************************************************************
2278
- * IMSHOW
2279
- *****************************************************************************/
2280
-
2281
- //void imshow_window_callback(imshow_t *imshow, const SDL_Event event) {
2282
- // if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
2283
- // SDL_Surface *screen_surface = SDL_GetWindowSurface(imshow->window);
2284
-
2285
- // Uint32 color = SDL_MapRGB(screen_surface->format, 0, 0, 0);
2286
- // SDL_FillRect(screen_surface, NULL, color);
2287
-
2288
- // SDL_Rect stretch;
2289
- // stretch.x = 0;
2290
- // stretch.y = 0;
2291
- // stretch.w = event.window.data1;
2292
- // stretch.h = event.window.data2;
2293
- // SDL_BlitScaled(imshow->image_surface, NULL, screen_surface, &stretch);
2294
- // }
2295
- //}
2296
-
2297
- //void imshow_keyboard_callback(imshow_t *imshow, const SDL_Event event) {
2298
- // if (event.type == SDL_KEYDOWN) {
2299
- // switch (event.key.keysym.sym) {
2300
- // case SDLK_ESCAPE:
2301
- // imshow->loop = 0;
2302
- // break;
2303
- // case SDLK_q:
2304
- // imshow->loop = 0;
2305
- // break;
2306
- // }
2307
- // }
2308
- //}
2309
-
2310
- //void imshow_event_handler(imshow_t *imshow) {
2311
- // SDL_Event event;
2312
- // while (SDL_PollEvent(&event)) {
2313
- // switch (event.type) {
2314
- // case SDL_WINDOWEVENT:
2315
- // imshow_window_callback(imshow, event);
2316
- // break;
2317
- // case SDL_KEYUP:
2318
- // case SDL_KEYDOWN:
2319
- // imshow_keyboard_callback(imshow, event);
2320
- // break;
2321
- // }
2322
- // }
2323
- //}
2324
-
2325
- //void draw_circle(SDL_Renderer *renderer,
2326
- // const int cx,
2327
- // const int cy,
2328
- // const int radius,
2329
- // const SDL_Color color) {
2330
- // SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
2331
- // for (int x = cx - radius; x <= cx + radius; x++) {
2332
- // for (int y = cy - radius; y <= cy + radius; y++) {
2333
- // if ((pow(cy - y, 2) + pow(cx - x, 2)) <= pow(radius, 2)) {
2334
- // SDL_RenderDrawPoint(renderer, x, y);
2335
- // }
2336
- // }
2337
- // }
2338
- //}
2339
-
2340
- //// void draw_circle(SDL_Renderer *renderer,
2341
- //// int32_t centreX,
2342
- //// int32_t centreY,
2343
- //// int32_t radius,
2344
- //// const SDL_Color color) {
2345
- //// SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
2346
- //// const int32_t diameter = (radius * 2);
2347
- ////
2348
- //// int32_t x = (radius - 1);
2349
- //// int32_t y = 0;
2350
- //// int32_t tx = 1;
2351
- //// int32_t ty = 1;
2352
- //// int32_t error = (tx - diameter);
2353
- ////
2354
- //// while (x >= y) {
2355
- //// // Each of the following renders an octant of the circle
2356
- //// SDL_RenderDrawPoint(renderer, centreX + x, centreY - y);
2357
- //// SDL_RenderDrawPoint(renderer, centreX + x, centreY + y);
2358
- //// SDL_RenderDrawPoint(renderer, centreX - x, centreY - y);
2359
- //// SDL_RenderDrawPoint(renderer, centreX - x, centreY + y);
2360
- //// SDL_RenderDrawPoint(renderer, centreX + y, centreY - x);
2361
- //// SDL_RenderDrawPoint(renderer, centreX + y, centreY + x);
2362
- //// SDL_RenderDrawPoint(renderer, centreX - y, centreY - x);
2363
- //// SDL_RenderDrawPoint(renderer, centreX - y, centreY + x);
2364
- ////
2365
- //// if (error <= 0) {
2366
- //// ++y;
2367
- //// error += ty;
2368
- //// ty += 2;
2369
- //// }
2370
- ////
2371
- //// if (error > 0) {
2372
- //// --x;
2373
- //// tx += 2;
2374
- //// error += (tx - diameter);
2375
- //// }
2376
- //// }
2377
- //// }
2378
-
2379
- //void imshow_setup(imshow_t *im, const char *fp) {
2380
- // // SDL init
2381
- // if (SDL_Init(SDL_INIT_VIDEO) != 0) {
2382
- // FATAL("SDL_Init Error: %s/n", SDL_GetError());
2383
- // }
2384
-
2385
- // // Load image
2386
- // im->image_surface = IMG_Load(fp);
2387
- // if (im->image_surface == NULL) {
2388
- // FATAL("Failed to load image [%s]!", fp);
2389
- // }
2390
- // const int img_w = im->image_surface->w;
2391
- // const int img_h = im->image_surface->h;
2392
-
2393
- // // Get display size
2394
- // SDL_DisplayMode disp_mode;
2395
- // SDL_GetCurrentDisplayMode(0, &disp_mode);
2396
- // const int disp_w = disp_mode.w;
2397
- // const int disp_h = disp_mode.h;
2398
-
2399
- // // Create window
2400
- // const int x = disp_w / 2 - img_w / 2;
2401
- // const int y = disp_h / 2 - img_h / 2;
2402
- // const int w = img_w;
2403
- // const int h = img_h;
2404
- // if (SDL_CreateWindowAndRenderer(w, h, 0, &im->window, &im->renderer) != 0) {
2405
- // FATAL("Failed to create window: %s\n", SDL_GetError());
2406
- // }
2407
- // SDL_SetWindowTitle(im->window, im->window_title);
2408
- // SDL_SetWindowPosition(im->window, x, y);
2409
- // SDL_SetWindowResizable(im->window, 1);
2410
-
2411
- // // Clear render
2412
- // SDL_SetRenderDrawColor(im->renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
2413
- // SDL_RenderClear(im->renderer);
2414
-
2415
- // // Show image
2416
- // SDL_Texture *texture =
2417
- // SDL_CreateTextureFromSurface(im->renderer, im->image_surface);
2418
- // SDL_RenderCopy(im->renderer, texture, NULL, NULL);
2419
- // SDL_RenderPresent(im->renderer);
2420
-
2421
- // // Draw circles
2422
- // const int x_min = 0;
2423
- // const int y_min = 0;
2424
- // const int x_max = img_w;
2425
- // const int y_max = img_h;
2426
- // for (int i = 0; i < 200; i++) {
2427
- // const int x = (rand() % (x_max + 1 - x_min)) + x_min;
2428
- // const int y = (rand() % (y_max + 1 - y_min)) + y_min;
2429
- // const int radius = 5;
2430
- // SDL_Color color;
2431
- // color.r = 255;
2432
- // color.g = 0;
2433
- // color.b = 0;
2434
- // color.a = 255;
2435
- // draw_circle(im->renderer, x, y, radius, color);
2436
- // }
2437
- // SDL_RenderPresent(im->renderer);
2438
-
2439
- // // Cursor
2440
- // im->left_click = 0;
2441
- // im->right_click = 0;
2442
- // im->last_cursor_set = 0;
2443
- // im->last_cursor_x = 0.0f;
2444
- // im->last_cursor_y = 0.0f;
2445
- //}
2446
-
2447
- //void imshow_reset(imshow_t *imshow) {
2448
- // // Camera
2449
- // imshow->movement_speed = 50.0f;
2450
- // imshow->mouse_sensitivity = 0.02f;
2451
-
2452
- // // Cursor
2453
- // imshow->left_click = 0;
2454
- // imshow->right_click = 0;
2455
- // imshow->last_cursor_set = 0;
2456
- // imshow->last_cursor_x = 0.0f;
2457
- // imshow->last_cursor_y = 0.0f;
2458
- //}
2459
-
2460
- //void imshow_loop(imshow_t *imshow) {
2461
- // imshow->loop = 1;
2462
- // while (imshow->loop) {
2463
- // imshow_event_handler(imshow);
2464
- // SDL_UpdateWindowSurface(imshow->window);
2465
- // SDL_Delay(1);
2466
- // }
2467
-
2468
- // SDL_DestroyWindow(imshow->window);
2469
- // SDL_Quit();
2470
- //}
2471
-
2472
2259
#endif // GUI_IMPLEMENTATION
2473
2260
2474
2261
//////////////////////////////////////////////////////////////////////////////
@@ -3056,32 +2843,8 @@ int test_gui() {
3056
2843
return 0 ;
3057
2844
}
3058
2845
3059
- // TEST IMSHOW ///////////////////////////////////////////////////////////////
3060
-
3061
- // int test_imshow() {
3062
- // imshow_t imshow;
3063
- // imshow.window_title = "Test";
3064
- // imshow_setup(&imshow, "test_data/images/awesomeface.png");
3065
-
3066
- // /* int x = 100; */
3067
- // /* int y = 100; */
3068
- // /* int radius = 10; */
3069
- // /* SDL_Color color; */
3070
- // /* color.r = 0; */
3071
- // /* color.g = 0; */
3072
- // /* color.b = 0; */
3073
- // /* color.a = 255; */
3074
- // /* draw_circle(imshow.renderer, x, y, radius, color); */
3075
-
3076
- // imshow_loop(&imshow);
3077
-
3078
- // return 0;
3079
- // }
3080
-
3081
2846
// TEST GLFW /////////////////////////////////////////////////////////////////
3082
2847
3083
- // #include <GLFW/glfw3.h>
3084
-
3085
2848
int test_glfw () {
3086
2849
if (!glfwInit ()) {
3087
2850
exit (EXIT_FAILURE );
@@ -3127,7 +2890,6 @@ int main(int argc, char *argv[]) {
3127
2890
// TEST(test_gl_model_load);
3128
2891
TEST (test_gui );
3129
2892
// TEST(test_glfw);
3130
- // TEST(test_imshow);
3131
2893
3132
2894
return (nb_failed ) ? -1 : 0 ;
3133
2895
}
0 commit comments