Very basic rendering with SDL1.2 + OGL

This commit is contained in:
Eduardo Bart 2013-02-26 01:34:40 -03:00
parent 65b32d283b
commit fb8552d142
11 changed files with 254 additions and 36 deletions

View File

@ -123,15 +123,20 @@ set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/otml/otmlparser.h ${CMAKE_CURRENT_LIST_DIR}/otml/otmlparser.h
# crash handler # crash handler
${CMAKE_CURRENT_LIST_DIR}/platform/crashhandler.h
${CMAKE_CURRENT_LIST_DIR}/platform/unixcrashhandler.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32platform.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/unixplatform.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/platform.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/platform.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/platform.h ${CMAKE_CURRENT_LIST_DIR}/platform/platform.h
) )
if(WIN32)
set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/win32platform.cpp
)
else()
set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/unixplatform.cpp
)
endif()
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
PROPERTIES LANGUAGE CXX COMPILE_FLAGS "-g0 -Os") PROPERTIES LANGUAGE CXX COMPILE_FLAGS "-g0 -Os")
@ -258,6 +263,15 @@ if(CRASH_HANDLER)
message(STATUS "Crash handler: ON") message(STATUS "Crash handler: ON")
if(WIN32) if(WIN32)
set(framework_LIBRARIES ${framework_LIBRARIES} imagehlp) set(framework_LIBRARIES ${framework_LIBRARIES} imagehlp)
set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/crashhandler.h
${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp
)
else()
set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/crashhandler.h
${CMAKE_CURRENT_LIST_DIR}/platform/unixcrashhandler.cpp
)
endif() endif()
else() else()
message(STATUS "Crash handler: OFF") message(STATUS "Crash handler: OFF")
@ -343,6 +357,32 @@ if(FRAMEWORK_GRAPHICS)
set(framework_LIBRARIES ${framework_LIBRARIES} X11) set(framework_LIBRARIES ${framework_LIBRARIES} X11)
endif() endif()
option(SDL "Use SDL support" OFF)
if(SDL)
find_package(SDL REQUIRED)
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DSDL)
set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} ${SDL_INCLUDE_DIR})
set(framework_LIBRARIES ${framework_LIBRARIES} ${SDL_LIBRARY})
set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/graphics/sdl/paintersdl.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/sdl/paintersdl.h
${CMAKE_CURRENT_LIST_DIR}/platform/sdlwindow.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/sdlwindow.h
)
else()
if(WIN32)
set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h
)
else()
set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.h
)
endif()
endif()
set(framework_SOURCES ${framework_SOURCES} set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/graphics/animatedtexture.cpp ${CMAKE_CURRENT_LIST_DIR}/graphics/animatedtexture.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/animatedtexture.h ${CMAKE_CURRENT_LIST_DIR}/graphics/animatedtexture.h
@ -435,10 +475,6 @@ if(FRAMEWORK_GRAPHICS)
# platform window # platform window
${CMAKE_CURRENT_LIST_DIR}/platform/platformwindow.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/platformwindow.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/platformwindow.h ${CMAKE_CURRENT_LIST_DIR}/platform/platformwindow.h
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.h
# window input # window input
${CMAKE_CURRENT_LIST_DIR}/input/mouse.cpp ${CMAKE_CURRENT_LIST_DIR}/input/mouse.cpp

View File

@ -23,8 +23,6 @@
#ifndef CRASHHANDLER_H #ifndef CRASHHANDLER_H
#define CRASHHANDLER_H #define CRASHHANDLER_H
#ifdef CRASH_HANDLER
void installCrashHandler(); void installCrashHandler();
#endif
#endif #endif

View File

@ -22,6 +22,10 @@
#include "platformwindow.h" #include "platformwindow.h"
#ifdef SDL
#include "sdlwindow.h"
SDLWindow window;
#else
#ifdef WIN32 #ifdef WIN32
#include "win32window.h" #include "win32window.h"
WIN32Window window; WIN32Window window;
@ -30,6 +34,7 @@ WIN32Window window;
#include <framework/core/clock.h> #include <framework/core/clock.h>
X11Window window; X11Window window;
#endif #endif
#endif
#include <framework/core/clock.h> #include <framework/core/clock.h>
#include <framework/graphics/image.h> #include <framework/graphics/image.h>

View File

@ -19,3 +19,163 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "sdlwindow.h"
SDLWindow::SDLWindow()
{
m_visual = 0;
m_display = 0;
}
void SDLWindow::init()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
g_logger.fatal(stdext::format("SDL video initialization failed: %s", SDL_GetError()));
m_visual = SDL_GetVideoInfo();
if(!m_visual)
g_logger.fatal(stdext::format("SDL video query failed: %s", SDL_GetError()));
int width = 640;
int height = 480;
int bpp = m_visual->vfmt->BitsPerPixel;
int flags = SDL_OPENGL | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
m_display = SDL_SetVideoMode(width, height, bpp, flags);
if(!m_display)
g_logger.fatal(stdext::format("SDL video mode set failed: %s", SDL_GetError()));
m_size = Size(width,height);
m_visible = true;
}
void SDLWindow::terminate()
{
SDL_Quit();
}
void SDLWindow::move(const Point& pos)
{
}
void SDLWindow::resize(const Size& size)
{
}
void SDLWindow::show()
{
}
void SDLWindow::hide()
{
}
void SDLWindow::maximize()
{
}
void SDLWindow::poll()
{
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_KEYDOWN:
break;
case SDL_MOUSEMOTION:
break;
case SDL_VIDEORESIZE:
break;
case SDL_QUIT:
if(m_onClose)
m_onClose();
default:
//printf("I don't know what this event is!\n");
break;
}
}
}
void SDLWindow::swapBuffers()
{
SDL_GL_SwapBuffers();
}
void SDLWindow::showMouse()
{
}
void SDLWindow::hideMouse()
{
}
void SDLWindow::setMouseCursor(int cursorId)
{
}
void SDLWindow::restoreMouseCursor()
{
}
void SDLWindow::setTitle(const std::string& title)
{
SDL_WM_SetCaption(title.c_str(), title.c_str());
}
void SDLWindow::setMinimumSize(const Size& minimumSize)
{
}
void SDLWindow::setFullscreen(bool fullscreen)
{
}
void SDLWindow::setVerticalSync(bool enable)
{
}
void SDLWindow::setIcon(const std::string& file)
{
}
void SDLWindow::setClipboardText(const std::string& text)
{
}
Size SDLWindow::getDisplaySize()
{
return m_size;
}
std::string SDLWindow::getClipboardText()
{
return std::string();
}
std::string SDLWindow::getPlatformType()
{
return "SDL";
}
int SDLWindow::internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot)
{
return 0;
}

View File

@ -23,4 +23,48 @@
#ifndef SDLWINDOW_H #ifndef SDLWINDOW_H
#define SDLWINDOW_H #define SDLWINDOW_H
#include "platformwindow.h"
#include <SDL.h>
#include <framework/graphics/glutil.h>
class SDLWindow : public PlatformWindow
{
public:
SDLWindow();
void init();
void terminate();
void move(const Point& pos);
void resize(const Size& size);
void show();
void hide();
void maximize();
void poll();
void swapBuffers();
void showMouse();
void hideMouse();
void setMouseCursor(int cursorId);
void restoreMouseCursor();
void setTitle(const std::string& title);
void setMinimumSize(const Size& minimumSize);
void setFullscreen(bool fullscreen);
void setVerticalSync(bool enable);
void setIcon(const std::string& file);
void setClipboardText(const std::string& text);
Size getDisplaySize();
std::string getClipboardText();
std::string getPlatformType();
protected:
int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
private:
const SDL_VideoInfo *m_visual;
SDL_Surface *m_display;
};
#endif #endif

View File

@ -20,8 +20,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#if !defined(WIN32) && defined(CRASH_HANDLER)
#include "crashhandler.h" #include "crashhandler.h"
#include <framework/global.h> #include <framework/global.h>
#include <framework/core/application.h> #include <framework/core/application.h>
@ -133,5 +131,3 @@ void installCrashHandler()
sigaction(SIGFPE, &sa, NULL); // floating-point exception sigaction(SIGFPE, &sa, NULL); // floating-point exception
sigaction(SIGABRT, &sa, NULL); // process aborted (asserts) sigaction(SIGABRT, &sa, NULL); // process aborted (asserts)
} }
#endif

View File

@ -20,8 +20,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef WIN32
#include "platform.h" #include "platform.h"
#include <fstream> #include <fstream>
#include <unistd.h> #include <unistd.h>
@ -167,6 +165,3 @@ std::string Platform::getOSName()
} }
return std::string(); return std::string();
} }
#endif

View File

@ -20,8 +20,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#if defined(WIN32) && defined(CRASH_HANDLER)
#include "crashhandler.h" #include "crashhandler.h"
#include <framework/global.h> #include <framework/global.h>
#include <framework/core/application.h> #include <framework/core/application.h>
@ -158,5 +156,3 @@ void installCrashHandler()
{ {
SetUnhandledExceptionFilter(ExceptionHandler); SetUnhandledExceptionFilter(ExceptionHandler);
} }
#endif

View File

@ -20,8 +20,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifdef WIN32
#include "platform.h" #include "platform.h"
#include <windows.h> #include <windows.h>
#include <framework/stdext/stdext.h> #include <framework/stdext/stdext.h>
@ -413,5 +411,3 @@ std::string Platform::getOSName()
} }
return ret; return ret;
} }
#endif

View File

@ -20,8 +20,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifdef WIN32
#include "win32window.h" #include "win32window.h"
#include <framework/graphics/image.h> #include <framework/graphics/image.h>
#include <framework/core/application.h> #include <framework/core/application.h>
@ -1019,5 +1017,3 @@ Rect WIN32Window::adjustWindowRect(const Rect& clientRect)
} }
return rect; return rect;
} }
#endif

View File

@ -20,8 +20,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef WIN32
#include "x11window.h" #include "x11window.h"
#include <framework/core/resourcemanager.h> #include <framework/core/resourcemanager.h>
#include <framework/graphics/image.h> #include <framework/graphics/image.h>
@ -1075,5 +1073,3 @@ std::string X11Window::getPlatformType()
return "X11-EGL"; return "X11-EGL";
#endif #endif
} }
#endif