aboutsummaryrefslogtreecommitdiff
path: root/lib/gdi/sdl.cpp
blob: e816a185c7541a5ff2f15ad14b6f9a1b2f61bbd7 (plain)
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
#include <lib/gdi/sdl.h>

#include <lib/base/init.h>
#include <lib/base/init_num.h>

#include <SDL.h>

gSDLDC::gSDLDC()
{
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		eWarning("Could not initialize SDL: %s", SDL_GetError());
		return;
	}

	setResolution(720, 576);

	CONNECT(m_pump.recv_msg, gSDLDC::pumpEvent);

	m_surface.type = 0;
	m_surface.clut.colors=256;
	m_surface.clut.data=new gRGB[m_surface.clut.colors];
	
	m_pixmap = new gPixmap(&m_surface);
	
	memset(m_surface.clut.data, 0, sizeof(*m_surface.clut.data)*m_surface.clut.colors);
}

gSDLDC::~gSDLDC()
{
	SDL_Quit();
}

void gSDLDC::setPalette()
{
	if (!m_surface.clut.data)
		return;
	
/*	for (int i=0; i<256; ++i)
	{
		fb->CMAP()->red[i]=ramp[m_surface.clut.data[i].r]<<8;
		fb->CMAP()->green[i]=ramp[m_surface.clut.data[i].g]<<8;
		fb->CMAP()->blue[i]=ramp[m_surface.clut.data[i].b]<<8;
		fb->CMAP()->transp[i]=rampalpha[m_surface.clut.data[i].a]<<8;
		if (!fb->CMAP()->red[i])
			fb->CMAP()->red[i]=0x100;
	}
	fb->PutCMAP(); */
}

void gSDLDC::exec(const gOpcode *o)
{
	switch (o->opcode)
	{
	case gOpcode::setPalette:
	{
		gDC::exec(o);
		setPalette();
		break;
	}
	case gOpcode::flush:
		SDL_Flip(m_screen);
		eDebug("FLUSH");
		break;
	default:
		gDC::exec(o);
		break;
	}
}

void gSDLDC::setResolution(int xres, int yres)
{
	m_screen = SDL_SetVideoMode(xres, yres, 32, SDL_HWSURFACE);
	if (!m_screen)
	{
		eWarning("Could not create SDL surface: %s", SDL_GetError());
		return;
	}

	m_surface.x = m_screen->w;
	m_surface.y = m_screen->h;
	m_surface.bpp = m_screen->format->BitsPerPixel;
	m_surface.bypp = m_screen->format->BytesPerPixel;
	m_surface.stride = m_screen->pitch;
	m_surface.data = m_screen->pixels;
}

eAutoInitPtr<gSDLDC> init_gSDLDC(eAutoInitNumbers::graphic-1, "gSDLDC");