Skip to content

Latest commit

 

History

History
145 lines (110 loc) · 4.08 KB

SDLTurtleSpaceRenderer.cpp

File metadata and controls

145 lines (110 loc) · 4.08 KB
 
Apr 18, 2001
Apr 18, 2001
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* TOBY -- An abstract interpreter engine and system for learning.
* Copyright (C) 1999 Ryan C. Gordon.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "platform/renderers/sdlrenderer/SDLTurtleSpaceRenderer.h"
SDLTurtleSpaceRenderer::SDLTurtleSpaceRenderer(Uint32 flags)
: FrameBufferTurtleSpaceRenderer(),
sdlflags(flags),
swsurface(NULL)
{
} // Constructor
SDLTurtleSpaceRenderer::~SDLTurtleSpaceRenderer(void)
{
deleteSurface();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
} // Destructor
bool SDLTurtleSpaceRenderer::screenResize(int _w, int _h)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return(false);
SDL_WM_SetCaption("Toby", "Toby");
SDL_Surface *screen = SDL_SetVideoMode(_w, _h, 32, sdlflags);
return(screen != NULL);
} // SDLTurtleSpaceRenderer::screenResize
void SDLTurtleSpaceRenderer::createSurface(int _w, int _h)
{
swsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, _w, _h, 32,
0x00FF0000, 0x0000FF00,
0x000000FF, 0xFF000000);
} // SDLTurtleSpaceRenderer::createSurface
void SDLTurtleSpaceRenderer::deleteSurface(void)
{
if (swsurface != NULL)
{
SDL_FreeSurface(swsurface);
swsurface = NULL;
} // if
} // SDLTurtleSpaceRenderer::deleteSurface
void SDLTurtleSpaceRenderer::putToScreen(toby_uint32 *pix,
int x, int y,
int w, int h)
{
assert(pix == swsurface->pixels);
SDL_Rect rect = {x, y, w, h};
SDL_Surface *screen = SDL_GetVideoSurface();
assert(screen != NULL);
if (SDL_MUSTLOCK(screen))
SDL_LockSurface(screen);
SDL_BlitSurface(swsurface, &rect, screen, &rect);
if (SDL_MUSTLOCK(screen))
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen, x, y, w, h); // !!! need this?
} // SDLTurtleSpaceRenderer::putToScreen
void SDLTurtleSpaceRenderer::putMultToScreen(toby_uint32 *pix, int rectCount,
FrameBufferRect *rects)
{
assert(pix == swsurface->pixels);
SDL_Surface *screen = SDL_GetVideoSurface();
assert(screen != NULL);
if (SDL_MUSTLOCK(screen))
SDL_LockSurface(screen);
for (int i = 0; i < rectCount; i++)
{
SDL_Rect r = {rects[i].x, rects[i].y, rects[i].w, rects[i].h};
SDL_BlitSurface(swsurface, &r, screen, &r);
SDL_UpdateRect(screen, r.x, r.y, r.w, r.h);
} // for
if (SDL_MUSTLOCK(screen))
SDL_UnlockSurface(screen);
// SDL_UpdateRects(screen, rectCount, (SDL_Rect *) rects); // !!! need this?
} // SDLTurtleSpaceRenderer::putToScreen
toby_uint32 *SDLTurtleSpaceRenderer::getSurface(void)
{
if (swsurface == NULL)
return(NULL);
return((toby_uint32 *) swsurface->pixels);
} // SDLTurtleSpaceRenderer::getSurface
TurtleSpaceRenderer *__platformBuildStandaloneRenderer(char *winTitle,
int *argc, char ***argv)
{
SDLTurtleSpaceRenderer *retval = new SDLTurtleSpaceRenderer(0);
SDL_WM_SetCaption(winTitle, winTitle);
return(retval);
} // __platformBuildStandaloneRenderer
bool __platformRendererDoEvents(void)
{
bool retval = true;
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
retval = false;
} // while
return(retval);
} // __platformRendererDoEvents
// end of SDLTurtleSpaceRenderer.cpp ...