All pastes #839997 Raw Edit

Untitled

public cpp v1 · immutable
#839997 ·published 2007-12-31 11:57 UTC
rendered paste body
	std::cout << "Starting Font Engine.. ";	if(TTF_Init() != -1)	{		std::cout << "OK.\n";		std::cout << "Loading Font.. ";		this->TextFont = TTF_OpenFont("../font/VeraMono.ttf", 10);		if(this->TextFont)		{			std::cout << "OK.\n";		}		else		{			std::cout << "FAILED.\n";			std::cerr << "SDL_TTF error message: " << TTF_GetError() << "\n";		}	}	else	{		std::cout << "FAILED.\n";		std::cerr << "SDL_TTF error message: " << TTF_GetError() << "\n";	}bool cVideoEngine::DrawText(int X, int Y, const char* Text, int Red, int Green, int Blue){	std::cout << "Printing Text(" << Text << ").. ";	SDL_Color TextColor = {Red, Green, Blue};	SDL_Surface* TextSurface;	TextSurface = TTF_RenderText_Shaded(this->TextFont, gettext(Text), TextColor, TextColor);	if(TextSurface)	{		std::cout << "OK.\n";	}	else	{		std::cout << "FAILED.\n";		std::cerr << "SDL_TTF error message: " << TTF_GetError() << "\n";	}	int TextSurfaceWidth = 1;	int TextSurfaceHeight = 1;	while(TextSurfaceWidth <= TextSurface->w) { TextSurfaceWidth *= 2; }	while(TextSurfaceHeight <= TextSurface->h) { TextSurfaceHeight *= 2; }	TextSurface = SDL_CreateRGBSurfaceFrom(TextSurface->pixels, TextSurfaceWidth, TextSurfaceHeight, 32, 0, 0, 0, 0, 0);	std::cout << "Size1: " << TextSurface->w << ", " << TextSurface->h << "\n";	std::cout << "Size2: " << TextSurfaceWidth << ", " << TextSurfaceHeight << "\n";	GLuint TextTexture;	glGenTextures(1, &TextTexture);	glBindTexture(GL_TEXTURE_2D, TextTexture);	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TextSurfaceWidth, TextSurfaceHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, TextSurface->pixels);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	glLoadIdentity();	glTranslatef(X, Y, 0);	glBindTexture(GL_TEXTURE_2D, TextTexture);	glBegin(GL_QUADS);		glTexCoord2f(0, 0);		glVertex2i(0, 0);		glTexCoord2f(0, (TextSurface->h / TextSurfaceHeight));		glVertex2i(0, TextSurface->h);		glTexCoord2f((TextSurface->w / TextSurfaceWidth), (TextSurface->h / TextSurfaceHeight));		glVertex2i(TextSurface->w, TextSurface->h);		glTexCoord2f((TextSurface->w / TextSurfaceWidth), 0);		glVertex2i(TextSurface->w, 0);	glEnd();	glLoadIdentity();	// Properly free the text surface.	SDL_FreeSurface(TextSurface);}