c99 conversion

This commit is contained in:
2024-03-12 20:12:26 +11:00
parent 01a0dd932e
commit 02484902ee
2 changed files with 9 additions and 8 deletions

View File

@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION "3.5" FATAL_ERROR) cmake_minimum_required(VERSION "3.5" FATAL_ERROR)
project(Lesson10 LANGUAGES CXX) project(Lesson10 LANGUAGES C)
find_package(SDL3 REQUIRED CONFIG) find_package(SDL3 REQUIRED CONFIG)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
add_executable(Lesson10 Lesson10.cpp) add_executable(Lesson10 Lesson10.c)
set_target_properties(Lesson10 PROPERTIES set_target_properties(Lesson10 PROPERTIES
CXX_STANDARD 98 C_STANDARD 99
WIN32_EXECUTABLE ON) WIN32_EXECUTABLE ON)
target_link_libraries(Lesson10 SDL3::SDL3 OpenGL::GL) target_link_libraries(Lesson10 SDL3::SDL3 OpenGL::GL)
target_compile_options(Lesson10 PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic>) target_compile_options(Lesson10 PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic>)

View File

@@ -9,6 +9,7 @@
#include <math.h> // Math Library Header File #include <math.h> // Math Library Header File
#include <stdio.h> // Header File For Standard Input/Output #include <stdio.h> // Header File For Standard Input/Output
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <SDL3/SDL_main.h> #include <SDL3/SDL_main.h>
#include <SDL3/SDL_opengl.h> // Header File For The OpenGL32 Library #include <SDL3/SDL_opengl.h> // Header File For The OpenGL32 Library
@@ -90,7 +91,7 @@ void SetupWorld()
readstr(filein, oneline); readstr(filein, oneline);
sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles); sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles);
sector1.triangle = new TRIANGLE[numtriangles]; sector1.triangle = malloc(sizeof(TRIANGLE) * numtriangles);
sector1.numtriangles = numtriangles; sector1.numtriangles = numtriangles;
for (int loop = 0; loop < numtriangles; loop++) for (int loop = 0; loop < numtriangles; loop++)
{ {
@@ -119,7 +120,7 @@ bool FlipSurface(SDL_Surface *surface)
const int pitch = surface->pitch; const int pitch = surface->pitch;
const int numrows = surface->h; const int numrows = surface->h;
unsigned char *pixels = (unsigned char *)surface->pixels; unsigned char *pixels = (unsigned char *)surface->pixels;
unsigned char *tmprow = new unsigned char[pitch]; unsigned char *tmprow = malloc(sizeof(unsigned char) * pitch);
unsigned char *row1 = pixels; unsigned char *row1 = pixels;
unsigned char *row2 = pixels + (numrows - 1) * pitch; unsigned char *row2 = pixels + (numrows - 1) * pitch;
@@ -134,7 +135,7 @@ bool FlipSurface(SDL_Surface *surface)
row2 -= pitch; row2 -= pitch;
} }
delete[] tmprow; free(tmprow);
SDL_UnlockSurface(surface); SDL_UnlockSurface(surface);
return true; return true;
} }