tibia-client/src/graphics.cpp

101 lines
2.5 KiB
C++
Raw Normal View History

2010-11-19 16:55:55 +01:00
/* The MIT License
*
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "graphics.h"
2010-11-19 13:37:02 +01:00
#include "logger.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include "texture.h"
Graphics g_graphics;
Graphics::Graphics()
{
}
Graphics::~Graphics()
{
}
void Graphics::init()
{
// setup opengl
glEnable(GL_ALPHA_TEST); // enable alpha by default
glAlphaFunc(GL_GREATER, 0.0f); // default alpha mode
glDisable(GL_DEPTH_TEST); // we are rendering 2D only, we don't need it
glEnable(GL_TEXTURE_2D); // enable textures by default
2010-11-19 13:37:02 +01:00
notice("GPU %s", (const char*)glGetString(GL_RENDERER));
notice("OpenGL %s", (const char*)glGetString(GL_VERSION));
}
void Graphics::terminate()
{
}
void Graphics::resize(int width, int height)
2010-11-23 16:30:43 +01:00
{
m_width = width;
m_height = height;
restoreViewport();
}
void Graphics::restoreViewport()
{
// resize gl viewport
glViewport(0, 0, m_width, m_height);
/*
0,0---------0,w
2010-11-23 16:30:43 +01:00
| |
| |
| |
h,0---------h,w
*/
// setup view region like above
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, m_width, m_height, 0.0f);
// back to model view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Graphics::beginRender()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
}
void Graphics::endRender()
{
}