The-Powder-Toy/src/graphics/OpenGLGraphics.cpp

113 lines
2.2 KiB
C++
Raw Normal View History

2012-07-06 10:06:26 -05:00
#include "Graphics.h"
2018-05-09 11:05:39 -05:00
#include "FontReader.h"
#include "common/tpt-thread.h"
2012-07-06 10:06:26 -05:00
#ifdef OGLI
static pthread_mutex_t gMutex = PTHREAD_MUTEX_INITIALIZER;
//static pthread_mutex_t TMPMUT = PTHREAD_MUTEX_INITIALIZER;
2012-07-06 10:06:26 -05:00
Graphics::Graphics():
sdl_scale(1)
2012-07-06 10:06:26 -05:00
{
// if(gMutex == TMPMUT)
2012-08-12 10:55:59 -05:00
// pthread_mutex_init (&gMutex, NULL);
LoadDefaults();
InitialiseTextures();
2012-07-06 10:06:26 -05:00
//Texture for main UI
}
void Graphics::LoadDefaults()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(0, WINDOWW*sdl_scale, 0, WINDOWH*sdl_scale, -1, 1);
glOrtho(0, WINDOWW*sdl_scale, WINDOWH*sdl_scale, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glRasterPos2i(0, WINDOWH);
glRasterPos2i(0, 0);
glPixelZoom(1, 1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void Graphics::InitialiseTextures()
{
2012-07-06 10:06:26 -05:00
glEnable(GL_TEXTURE_2D);
2012-07-06 10:06:26 -05:00
glGenTextures(1, &vidBuf);
glBindTexture(GL_TEXTURE_2D, vidBuf);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WINDOWW, WINDOWH, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
2012-07-06 10:06:26 -05:00
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
2012-07-06 10:06:26 -05:00
glBindTexture(GL_TEXTURE_2D, 0);
2012-07-06 10:06:26 -05:00
glGenTextures(1, &textTexture);
glBindTexture(GL_TEXTURE_2D, textTexture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2012-07-06 10:06:26 -05:00
glBindTexture(GL_TEXTURE_2D, 0);
2012-07-06 10:06:26 -05:00
glDisable(GL_TEXTURE_2D);
}
void Graphics::DestroyTextures()
{
//Todo...
}
void Graphics::Acquire()
{
pthread_mutex_lock(&gMutex);
}
void Graphics::Release()
{
pthread_mutex_unlock(&gMutex);
}
2012-07-06 10:06:26 -05:00
Graphics::~Graphics()
{
}
void Graphics::Reset()
{
LoadDefaults();
DestroyTextures();
InitialiseTextures();
2012-07-06 10:06:26 -05:00
}
void Graphics::Clear()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
void Graphics::Finalise()
{
glFlush();
}
#define VIDXRES WINDOWW
#define VIDYRES WINDOWH
2012-07-06 10:06:26 -05:00
#define PIXELMETHODS_CLASS Graphics
2012-07-26 09:06:06 -05:00
#include "OpenGLDrawMethods.inl"
2012-07-06 10:06:26 -05:00
#undef VIDYRES
#undef VIDXRES
#undef PIXELMETHODS_CLASS
#endif