Skip to content

Commit e33788f

Browse files
committed
First commit.
0 parents  commit e33788f

File tree

14 files changed

+906
-0
lines changed

14 files changed

+906
-0
lines changed

CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.4)
2+
3+
project(SDLJumpStart)
4+
5+
# set(CMAKE_CXX_STANDARD 11)
6+
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long")
7+
8+
# includes cmake/FindSDL2.cmake
9+
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
10+
set(SDL2_PATH ${PROJECT_SOURCE_DIR}/third_party/sdl ${PROJECT_SOURCE_DIR}/third_party/sdl/make)
11+
find_package(SDL2 REQUIRED)
12+
find_package(OpenGL REQUIRED)
13+
14+
# find_package(GLEW REQUIRED)
15+
16+
17+
# target_include_directories(SDLJumpStart
18+
# ${OPENGL_INCLUDE_DIR}
19+
# ${GLEW_INCLUDE_DIRS})
20+
21+
22+
# include_directories("${SDL2_INCLUDE_DIR}")
23+
24+
add_executable(SDLJumpStart
25+
src/AssertMsg.cpp
26+
src/sdl_gl_texture.cpp
27+
src/engine.cpp
28+
src/font.cpp
29+
src/main.cpp
30+
)
31+
32+
target_include_directories(SDLJumpStart PUBLIC
33+
"${SDL2_INCLUDE_DIR}")
34+
35+
# project, [libs, ...]
36+
# ok to call multiple times on a single target.
37+
# PROJECT PRIVATE/PUBLIC/??? [LIB, ...]
38+
39+
target_link_libraries(SDLJumpStart
40+
"${SDL2_LIBRARY}"
41+
"${OPENGL_LIBRARIES}")

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 John Butterfield
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SDLJumpStart
2+
Basic structure of an engine, suitable as a starting point to develop a realtime application.
3+
4+
## Dependencies
5+
C++98 compatible.
6+
OpenGL
7+
SDL2 (this is the only one you need to download.)
8+
9+
## Build
10+
Run cmake from a temporary directory like this:
11+
12+
```
13+
mkdir build
14+
cd build
15+
cmake ..
16+
make
17+
cd ..
18+
```
19+
20+
## Run
21+
Run the binary. If successful an app with an OpenGL window should show.
22+
23+
```
24+
build/PlasmaSim
25+
```
26+
27+
## Notes
28+
This is really minimal barebones stuff, often designed for using the completely deprecated opengl fixed function pipeline,
29+
just because it's easy and convenient and the rendering quality is not important for many of the apps I often build.
30+
31+
In the future, I'll probably build a cleaner Fixed Function-like alternative, that has an immediate mode API to build primitives,
32+
and a standard shader for rendering those primitives.
33+

cmake/FindSDL2.cmake

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
2+
# This module defines
3+
# SDL2_LIBRARY, the name of the library to link against
4+
# SDL2_FOUND, if false, do not try to link to SDL2
5+
# SDL2_INCLUDE_DIR, where to find SDL.h
6+
#
7+
# This module responds to the the flag:
8+
# SDL2_BUILDING_LIBRARY
9+
# If this is defined, then no SDL2main will be linked in because
10+
# only applications need main().
11+
# Otherwise, it is assumed you are building an application and this
12+
# module will attempt to locate and set the the proper link flags
13+
# as part of the returned SDL2_LIBRARY variable.
14+
#
15+
# Don't forget to include SDLmain.h and SDLmain.m your project for the
16+
# OS X framework based version. (Other versions link to -lSDL2main which
17+
# this module will try to find on your behalf.) Also for OS X, this
18+
# module will automatically add the -framework Cocoa on your behalf.
19+
#
20+
#
21+
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
22+
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
23+
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
24+
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
25+
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
26+
# as appropriate. These values are used to generate the final SDL2_LIBRARY
27+
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
28+
#
29+
#
30+
# $SDL2DIR is an environment variable that would
31+
# correspond to the ./configure --prefix=$SDL2DIR
32+
# used in building SDL2.
33+
# l.e.galup 9-20-02
34+
#
35+
# Modified by Eric Wing.
36+
# Added code to assist with automated building by using environmental variables
37+
# and providing a more controlled/consistent search behavior.
38+
# Added new modifications to recognize OS X frameworks and
39+
# additional Unix paths (FreeBSD, etc).
40+
# Also corrected the header search path to follow "proper" SDL guidelines.
41+
# Added a search for SDL2main which is needed by some platforms.
42+
# Added a search for threads which is needed by some platforms.
43+
# Added needed compile switches for MinGW.
44+
#
45+
# On OSX, this will prefer the Framework version (if found) over others.
46+
# People will have to manually change the cache values of
47+
# SDL2_LIBRARY to override this selection or set the CMake environment
48+
# CMAKE_INCLUDE_PATH to modify the search paths.
49+
#
50+
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
51+
# This needed to change because "proper" SDL convention
52+
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
53+
# reasons because not all systems place things in SDL2/ (see FreeBSD).
54+
55+
#=============================================================================
56+
# Copyright 2003-2009 Kitware, Inc.
57+
#
58+
# Distributed under the OSI-approved BSD License (the "License");
59+
# see accompanying file Copyright.txt for details.
60+
#
61+
# This software is distributed WITHOUT ANY WARRANTY; without even the
62+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
63+
# See the License for more information.
64+
#=============================================================================
65+
# (To distribute this file outside of CMake, substitute the full
66+
# License text for the above reference.)
67+
68+
# message("<FindSDL2.cmake>")
69+
70+
SET(SDL2_SEARCH_PATHS
71+
~/Library/Frameworks
72+
/Library/Frameworks
73+
/usr/local
74+
/usr
75+
/sw # Fink
76+
/opt/local # DarwinPorts
77+
/opt/csw # Blastwave
78+
/opt
79+
${SDL2_PATH}
80+
)
81+
82+
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
83+
HINTS
84+
$ENV{SDL2DIR}
85+
PATH_SUFFIXES include/SDL2 include
86+
PATHS ${SDL2_SEARCH_PATHS}
87+
)
88+
89+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
90+
set(PATH_SUFFIXES lib64 lib/x64 lib)
91+
else()
92+
set(PATH_SUFFIXES lib/x86 lib)
93+
endif()
94+
95+
FIND_LIBRARY(SDL2_LIBRARY_TEMP
96+
NAMES SDL2
97+
HINTS
98+
$ENV{SDL2DIR}
99+
PATH_SUFFIXES ${PATH_SUFFIXES}
100+
PATHS ${SDL2_SEARCH_PATHS}
101+
)
102+
103+
IF(NOT SDL2_BUILDING_LIBRARY)
104+
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
105+
# Non-OS X framework versions expect you to also dynamically link to
106+
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
107+
# seem to provide SDL2main for compatibility even though they don't
108+
# necessarily need it.
109+
FIND_LIBRARY(SDL2MAIN_LIBRARY
110+
NAMES SDL2main
111+
HINTS
112+
$ENV{SDL2DIR}
113+
PATH_SUFFIXES ${PATH_SUFFIXES}
114+
PATHS ${SDL2_SEARCH_PATHS}
115+
)
116+
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
117+
ENDIF(NOT SDL2_BUILDING_LIBRARY)
118+
119+
# SDL2 may require threads on your system.
120+
# The Apple build may not need an explicit flag because one of the
121+
# frameworks may already provide it.
122+
# But for non-OSX systems, I will use the CMake Threads package.
123+
IF(NOT APPLE)
124+
FIND_PACKAGE(Threads)
125+
ENDIF(NOT APPLE)
126+
127+
# MinGW needs an additional link flag, -mwindows
128+
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
129+
IF(MINGW)
130+
SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW")
131+
ENDIF(MINGW)
132+
133+
IF(SDL2_LIBRARY_TEMP)
134+
# For SDL2main
135+
IF(NOT SDL2_BUILDING_LIBRARY)
136+
IF(SDL2MAIN_LIBRARY)
137+
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
138+
ENDIF(SDL2MAIN_LIBRARY)
139+
ENDIF(NOT SDL2_BUILDING_LIBRARY)
140+
141+
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
142+
# CMake doesn't display the -framework Cocoa string in the UI even
143+
# though it actually is there if I modify a pre-used variable.
144+
# I think it has something to do with the CACHE STRING.
145+
# So I use a temporary variable until the end so I can set the
146+
# "real" variable in one-shot.
147+
IF(APPLE)
148+
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
149+
ENDIF(APPLE)
150+
151+
# For threads, as mentioned Apple doesn't need this.
152+
# In fact, there seems to be a problem if I used the Threads package
153+
# and try using this line, so I'm just skipping it entirely for OS X.
154+
IF(NOT APPLE)
155+
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
156+
ENDIF(NOT APPLE)
157+
158+
# For MinGW library
159+
IF(MINGW)
160+
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
161+
ENDIF(MINGW)
162+
163+
# Set the final string here so the GUI reflects the final state.
164+
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
165+
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
166+
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
167+
ENDIF(SDL2_LIBRARY_TEMP)
168+
169+
# message("</FindSDL2.cmake>")
170+
171+
INCLUDE(FindPackageHandleStandardArgs)
172+
173+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)

images/font.bmp

65.1 KB
Binary file not shown.

src/AssertMsg.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
3+
void CustomAssertMsg(const char* expr_str, bool expr, const char* file, int line, const char* msg)
4+
{
5+
if (!expr)
6+
{
7+
std::cerr << "Assert failed:\t" << msg << "\n"
8+
<< "Expected:\t" << expr_str << "\n"
9+
<< "Source:\t\t" << file << ", line " << line << "\n";
10+
abort();
11+
}
12+
}

src/AssertMsg.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef ASSERT_MSG_H
2+
#define ASSERT_MSG_H
3+
4+
#ifndef NDEBUG
5+
#define ASSERT_MSG(Expr, Msg) CustomAssertMsg(#Expr, Expr, __FILE__, __LINE__, Msg)
6+
#else
7+
#define ASSERT_MSG(Expr, Msg) ;
8+
#endif
9+
10+
void CustomAssertMsg(const char* expr_str, bool expr, const char* file, int line, const char* msg);
11+
12+
#endif // ASSERT_MSG_H

0 commit comments

Comments
 (0)