CharacterAnimation::CharacterAnimation(std::string filename){
	mActualFrame = 0;
	mImage = loadImage(filename);
	SDL_Rect tile;
	tile.w = CHARSET_WIDTH;
	tile.h = CHARSET_HEIGHT;
	for(int y = 0; y < CHARSET_ANIMATION_ROWS; y++){
		for(int x = 0; x < CHARSET_ANIMATION_COLUMNS; x++){
			mFrames[y*CHARSET_ANIMATION_COLUMNS+x] = createEmptySurface(CHARSET_WIDTH, CHARSET_HEIGHT);
			tile.x = x*CHARSET_WIDTH;
			tile.y = y*CHARSET_HEIGHT;
			drawImage(0, 0, mImage, mFrames[y*CHARSET_ANIMATION_COLUMNS+x], &tile);
		}
	}
}
Example #2
0
void RenderManagerGL2D::init(int xResolution, int yResolution, bool fullscreen)
{
	glDisable(GL_DEPTH_TEST);
	mCurrentFlags.insert(GL_MULTISAMPLE);
	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_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	// Set modesetting
	Uint32 screenFlags = SDL_WINDOW_OPENGL;
	if (fullscreen)
		screenFlags |= SDL_WINDOW_FULLSCREEN;

	// Create window
	mWindow = SDL_CreateWindow(AppTitle,
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		xResolution, yResolution,
		screenFlags);

	// Set icon
	SDL_Surface* icon = loadSurface("Icon.bmp");
	SDL_SetColorKey(icon, SDL_TRUE,
			SDL_MapRGB(icon->format, 0, 0, 0));
	SDL_SetWindowIcon(mWindow, icon);
	SDL_FreeSurface(icon);

	// Create gl context
	mGlContext = SDL_GL_CreateContext(mWindow);

	SDL_ShowCursor(0);
	glDisable(GL_MULTISAMPLE);

	mLeftBlobColor = Color(255, 0, 0);
	mRightBlobColor = Color(0, 255, 0);
	glEnable(GL_TEXTURE_2D);

	// Load background
	SDL_Surface* bgSurface = loadSurface("backgrounds/strand2.bmp");
	BufferedImage* bgBufImage = new BufferedImage;
	bgBufImage->w = getNextPOT(bgSurface->w);
	bgBufImage->h = getNextPOT(bgSurface->h);
	bgBufImage->glHandle = loadTexture(bgSurface, false);
	mBackground = bgBufImage->glHandle;
	mImageMap["background"] = bgBufImage;

	mBallShadow = loadTexture(loadSurface("gfx/schball.bmp"), false);

	for (int i = 1; i <= 16; ++i)
	{
		char filename[64];
		sprintf(filename, "gfx/ball%02d.bmp", i);
		GLuint ballImage = loadTexture(loadSurface(filename), false);
		mBall.push_back(ballImage);
	}

	for (int i = 1; i <= 5; ++i)
	{
		char filename[64];
		sprintf(filename, "gfx/blobbym%d.bmp", i);
		GLuint blobImage = loadTexture(loadSurface(filename), false);
		mBlob.push_back(blobImage);
		sprintf(filename, "gfx/blobbym%d.bmp", i);
		GLuint blobSpecular = loadTexture(loadSurface(filename), true);
		mBlobSpecular.push_back(blobSpecular);
		sprintf(filename, "gfx/sch1%d.bmp", i);
		GLuint blobShadow = loadTexture(loadSurface(filename), false);
		mBlobShadow.push_back(blobShadow);
	}

	// create text base textures
	SDL_Surface* textbase = createEmptySurface(2048, 32);
	SDL_Surface* hltextbase = createEmptySurface(2048, 32);

	int x = 0;
	int sx = 0;

	for (int i = 0; i <= 54; ++i)
	{
		char filename[64];
		sprintf(filename, "gfx/font%02d.bmp", i);
		SDL_Surface* fontSurface = loadSurface(filename);

		SDL_Surface* highlight = highlightSurface(fontSurface, 60);

		SDL_Rect r = {(Uint16)x, 0, (Uint16)fontSurface->w, (Uint16)fontSurface->h};
		SDL_BlitSurface(fontSurface, 0, textbase, &r);
		SDL_BlitSurface(highlight, 0, hltextbase, &r);
		r.x = sx;
		r.y = 0;
		Texture s = Texture(0, x, 0, fontSurface->w, fontSurface->h, 2048, 32);
		mFont.push_back(s);
		mHighlightFont.push_back(s);

		x += fontSurface->w;

		SDL_FreeSurface(fontSurface);
	}

	GLuint texture =  loadTexture(textbase, false);
	GLuint hltexture =  loadTexture(hltextbase, false);
	for (unsigned int i = 0; i < mFont.size(); ++i)
	{
		mFont[i].texture = texture;
		mHighlightFont[i].texture = hltexture;
	}

	mParticle = loadTexture(loadSurface("gfx/blood.bmp"), false);

	glViewport(0, 0, xResolution, yResolution);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, 800, 600, 0, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);

	glAlphaFunc(GL_GREATER, 0.5);
	glEnable(GL_ALPHA_TEST);
}
void RenderManagerGL2D::init(int xResolution, int yResolution, bool fullscreen)
{
	mCurrentFlags.insert(GL_DEPTH_TEST);
	mCurrentFlags.insert(GL_MULTISAMPLE);
	
	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_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	
	Uint32 screenFlags = SDL_OPENGL;
	if (fullscreen)
		screenFlags |= SDL_FULLSCREEN;
	SDL_WM_SetCaption(AppTitle, "");
	SDL_WM_SetIcon(SDL_LoadBMP("data/Icon.bmp"), NULL);
	SDL_SetVideoMode(xResolution, yResolution, 0, screenFlags);
	SDL_ShowCursor(0);
	glDisable(GL_MULTISAMPLE);
	
	mLeftBlobColor = Color(255, 0, 0);
	mRightBlobColor = Color(0, 255, 0);

	SDL_Surface* bgSurface = loadSurface("backgrounds/strand2.bmp");
	BufferedImage* bgBufImage = new BufferedImage;
	bgBufImage->w = getNextPOT(bgSurface->w);
	bgBufImage->h = getNextPOT(bgSurface->h);
	bgBufImage->glHandle = loadTexture(bgSurface, false);
	mBackground = bgBufImage->glHandle;
	mImageMap["background"] = bgBufImage;
	
	mBallShadow = loadTexture(loadSurface("gfx/schball.bmp"), false);	
	mScroll = loadTexture(loadSurface("gfx/scrollbar.bmp"), false);

	for (int i = 1; i <= 16; ++i)
	{
		char filename[64];
		sprintf(filename, "gfx/ball%02d.bmp", i);
		GLuint ballImage = loadTexture(loadSurface(filename), false);
		mBall.push_back(ballImage);
	}

	for (int i = 1; i <= 5; ++i)
	{
		char filename[64];
		sprintf(filename, "gfx/blobbym%d.bmp", i);
		GLuint blobImage = loadTexture(loadSurface(filename), false);
		mBlob.push_back(blobImage);
		sprintf(filename, "gfx/blobbym%d.bmp", i);
		GLuint blobSpecular = loadTexture(loadSurface(filename), true);
		mBlobSpecular.push_back(blobSpecular);
		sprintf(filename, "gfx/sch1%d.bmp", i);
		GLuint blobShadow = loadTexture(loadSurface(filename), false);
		mBlobShadow.push_back(blobShadow);
	}

	// create text base textures
	SDL_Surface* textbase = createEmptySurface(2048, 32);
	SDL_Surface* hltextbase = createEmptySurface(2048, 32);
	SDL_Surface* smalltextbase = createEmptySurface(1024, 16);
	SDL_Surface* hlsmalltextbase = createEmptySurface(1024, 16);
	int x = 0;
	int sx = 0;

	for (int i = 0; i <= 53; ++i)
	{
		char filename[64], filename2[64];
		sprintf(filename, "gfx/font%02d.bmp", i);
		sprintf(filename2, "gfx/font_small/font%02d.bmp", i);
		SDL_Surface* fontSurface = loadSurface(filename);
		SDL_Surface* fontSurface2 = loadSurface(filename2);
		
		GLuint newFont = loadTexture(loadSurface(filename), false);
		GLuint newFont2 = loadTexture(loadSurface(filename2), false);
		SDL_Surface* highlight = highlightSurface(fontSurface, 60);
		SDL_Surface* highlight2 = highlightSurface(fontSurface2, 60);
		SDL_FreeSurface(fontSurface);
		SDL_FreeSurface(fontSurface2);
		
		fontSurface = loadSurface(filename);
		fontSurface2 = loadSurface(filename2);
		
		SDL_Rect r = {x, 0, fontSurface->w, fontSurface->h};
		SDL_BlitSurface(fontSurface, 0, textbase, &r);
		SDL_BlitSurface(highlight, 0, hltextbase, &r);
		r = {sx, 0, fontSurface2->w, fontSurface2->h};
		SDL_BlitSurface(fontSurface2, 0, smalltextbase, &r);
		SDL_BlitSurface(highlight2, 0, hlsmalltextbase, &r);
		//GLuint ballImage = loadTexture(sf, false);
		//mBall.push_back(ballImage);
		Texture s = Texture(0, x, 0, fontSurface->w, fontSurface->h, 2048, 32);
		mFont.push_back(s);
		mHighlightFont.push_back(s);
		
		s = Texture(0, sx, 0, fontSurface2->w, fontSurface2->h, 1024, 16);
		
		//mFont.push_back(newFont);
		//mHighlightFont.push_back(loadTexture(highlight, false));
		mSmallFont.push_back( s );
		mHighlightSmallFont.push_back( s );
		
		x += fontSurface->w;
		sx += fontSurface2->w;
		
		SDL_FreeSurface(fontSurface);
		SDL_FreeSurface(fontSurface2);
	}

	GLuint texture =  loadTexture(textbase, false);
	GLuint hltexture =  loadTexture(hltextbase, false);
	GLuint smalltexture =  loadTexture(smalltextbase, false);
	GLuint hlsmalltexture =  loadTexture(hlsmalltextbase, false);
	for (int i = 0; i < mFont.size(); ++i)
	{
		mFont[i].texture = texture;
		mHighlightFont[i].texture = hltexture;
		mSmallFont[i].texture = smalltexture;
		mHighlightSmallFont[i].texture = hlsmalltexture;
	}

	mParticle = loadTexture(loadSurface("gfx/blood.bmp"), false);

	glViewport(0, 0, xResolution, yResolution);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, 800, 600, 0, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glClearDepth(1.0);
	glDepthFunc(GL_LEQUAL);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);

	glAlphaFunc(GL_GREATER, 0.5);
	glEnable(GL_ALPHA_TEST);
}