mirror of
https://github.com/ScrelliCopter/Lesson10-SDL3.git
synced 2025-02-21 07:19:26 +11:00
sdl3
This commit is contained in:
@@ -3,9 +3,17 @@ project(Lesson10 LANGUAGES CXX)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 98)
|
set(CMAKE_CXX_STANDARD 98)
|
||||||
|
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL3 REQUIRED CONFIG)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
add_executable(Lesson10 Lesson10.cpp)
|
add_executable(Lesson10 Lesson10.cpp)
|
||||||
target_link_libraries(Lesson10 SDL2::SDL2 OpenGL::GL)
|
set_property(TARGET Lesson10 PROPERTY CXX_STANDARD 98)
|
||||||
|
target_link_libraries(Lesson10 SDL3::SDL3 OpenGL::GL)
|
||||||
target_compile_options(Lesson10 PRIVATE -Wall -Wextra -pedantic)
|
target_compile_options(Lesson10 PRIVATE -Wall -Wextra -pedantic)
|
||||||
|
|
||||||
|
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||||
|
get_property(SDL3_IMPORTED_LOCATION TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION)
|
||||||
|
if (SDL3_IMPORTED_LOCATION MATCHES "^/Library/Frameworks/")
|
||||||
|
target_link_options(Lesson10 PRIVATE -Wl,-rpath,/Library/Frameworks)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|||||||
27
Lesson10.cpp
27
Lesson10.cpp
@@ -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 <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <SDL_main.h>
|
||||||
#include <SDL_opengl.h> // Header File For The OpenGL32 Library
|
#include <SDL_opengl.h> // Header File For The OpenGL32 Library
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <OpenGL/glu.h> // Header File For The GLu32 Library
|
#include <OpenGL/glu.h> // Header File For The GLu32 Library
|
||||||
@@ -171,7 +172,7 @@ int LoadGLTextures() // Load Bitmaps And Conv
|
|||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
||||||
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage->w, TextureImage->h, GL_BGR, GL_UNSIGNED_BYTE, TextureImage->pixels);
|
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage->w, TextureImage->h, GL_BGR, GL_UNSIGNED_BYTE, TextureImage->pixels);
|
||||||
}
|
}
|
||||||
SDL_FreeSurface(TextureImage); // Free The Image Structure
|
SDL_DestroySurface(TextureImage); // Free The Image Structure
|
||||||
|
|
||||||
return Status; // Return The Status
|
return Status; // Return The Status
|
||||||
}
|
}
|
||||||
@@ -272,7 +273,7 @@ GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
|
|||||||
if (fullscreen) // Are We In Fullscreen Mode?
|
if (fullscreen) // Are We In Fullscreen Mode?
|
||||||
{
|
{
|
||||||
SDL_SetWindowFullscreen(hWnd, 0); // If So Switch Back To The Desktop
|
SDL_SetWindowFullscreen(hWnd, 0); // If So Switch Back To The Desktop
|
||||||
SDL_ShowCursor(SDL_ENABLE); // Show Mouse Pointer
|
SDL_ShowCursor(); // Show Mouse Pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hRC) // Do We Have A Rendering Context?
|
if (hRC) // Do We Have A Rendering Context?
|
||||||
@@ -311,7 +312,6 @@ bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
|
|||||||
|
|
||||||
// Create The Window
|
// Create The Window
|
||||||
if (!(hWnd = SDL_CreateWindow(title,
|
if (!(hWnd = SDL_CreateWindow(title,
|
||||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, // Window Position
|
|
||||||
WindowRect.w, // Window Width
|
WindowRect.w, // Window Width
|
||||||
WindowRect.h, // Window Height
|
WindowRect.h, // Window Height
|
||||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE)))
|
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE)))
|
||||||
@@ -323,7 +323,7 @@ bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
|
|||||||
|
|
||||||
if (fullscreen) // Attempt Fullscreen Mode?
|
if (fullscreen) // Attempt Fullscreen Mode?
|
||||||
{
|
{
|
||||||
if (SDL_SetWindowFullscreen(hWnd, SDL_WINDOW_FULLSCREEN_DESKTOP) < 0) // Try To Set Selected Mode And Get Results.
|
if (SDL_SetWindowFullscreen(hWnd, SDL_TRUE) < 0) // Try To Set Selected Mode And Get Results.
|
||||||
{
|
{
|
||||||
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
|
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
|
||||||
const SDL_MessageBoxData msgbox =
|
const SDL_MessageBoxData msgbox =
|
||||||
@@ -400,29 +400,22 @@ void WndProc(SDL_Event* uMsg)
|
|||||||
{
|
{
|
||||||
switch (uMsg->type) // Check For Windows Messages
|
switch (uMsg->type) // Check For Windows Messages
|
||||||
{
|
{
|
||||||
case SDL_KEYDOWN: // Is A Key Being Held Down?
|
case SDL_EVENT_KEY_DOWN: // Is A Key Being Held Down?
|
||||||
{
|
{
|
||||||
keys[uMsg->key.keysym.scancode] = true; // If So, Mark It As TRUE
|
keys[uMsg->key.keysym.scancode] = true; // If So, Mark It As TRUE
|
||||||
break; // Jump Back
|
break; // Jump Back
|
||||||
}
|
}
|
||||||
|
|
||||||
case SDL_KEYUP: // Has A Key Been Released?
|
case SDL_EVENT_KEY_UP: // Has A Key Been Released?
|
||||||
{
|
{
|
||||||
keys[uMsg->key.keysym.scancode] = false; // If So, Mark It As FALSE
|
keys[uMsg->key.keysym.scancode] = false; // If So, Mark It As FALSE
|
||||||
break; // Jump Back
|
break; // Jump Back
|
||||||
}
|
}
|
||||||
|
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: // Resize The OpenGL Window
|
||||||
{
|
{
|
||||||
switch (uMsg->window.event)
|
ReSizeGLScene(uMsg->window.data1,uMsg->window.data2); // LoWord=Width, HiWord=Height
|
||||||
{
|
break; // Jump Back
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED: // Resize The OpenGL Window
|
|
||||||
{
|
|
||||||
ReSizeGLScene(uMsg->window.data1,uMsg->window.data2); // LoWord=Width, HiWord=Height
|
|
||||||
break; // Jump Back
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,7 +455,7 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
if (SDL_PollEvent(&msg) > 0) // Is There A Message Waiting?
|
if (SDL_PollEvent(&msg) > 0) // Is There A Message Waiting?
|
||||||
{
|
{
|
||||||
if (msg.type==SDL_QUIT) // Have We Received A Quit Message?
|
if (msg.type==SDL_EVENT_QUIT) // Have We Received A Quit Message?
|
||||||
{
|
{
|
||||||
done=true; // If So done=TRUE
|
done=true; // If So done=TRUE
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user