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)
project(Lesson10 LANGUAGES CXX)
project(Lesson10 LANGUAGES C)
find_package(SDL3 REQUIRED CONFIG)
find_package(OpenGL REQUIRED)
add_executable(Lesson10 Lesson10.cpp)
add_executable(Lesson10 Lesson10.c)
set_target_properties(Lesson10 PROPERTIES
CXX_STANDARD 98
C_STANDARD 99
WIN32_EXECUTABLE ON)
target_link_libraries(Lesson10 SDL3::SDL3 OpenGL::GL)
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 <stdio.h> // Header File For Standard Input/Output
#include <stdlib.h>
#include <stdbool.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_opengl.h> // Header File For The OpenGL32 Library
@@ -90,7 +91,7 @@ void SetupWorld()
readstr(filein, oneline);
sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles);
sector1.triangle = new TRIANGLE[numtriangles];
sector1.triangle = malloc(sizeof(TRIANGLE) * numtriangles);
sector1.numtriangles = numtriangles;
for (int loop = 0; loop < numtriangles; loop++)
{
@@ -118,11 +119,11 @@ bool FlipSurface(SDL_Surface *surface)
const int pitch = surface->pitch;
const int numrows = surface->h;
unsigned char *pixels = (unsigned char*)surface->pixels;
unsigned char *tmprow = new unsigned char[pitch];
unsigned char *pixels = (unsigned char *)surface->pixels;
unsigned char *tmprow = malloc(sizeof(unsigned char) * pitch);
unsigned char *row1 = pixels;
unsigned char *row2 = pixels + (numrows- 1) * pitch;
unsigned char *row2 = pixels + (numrows - 1) * pitch;
for (int i = 0; i < numrows / 2; ++i)
{
// Swap rows
@@ -134,7 +135,7 @@ bool FlipSurface(SDL_Surface *surface)
row2 -= pitch;
}
delete[] tmprow;
free(tmprow);
SDL_UnlockSurface(surface);
return true;
}