#include "render.h" #include // solid quad int renderSQuad(int x, int y, int width, int height, SDL_Color color) { // reset view glLoadIdentity(); // translate to a quad glTranslated(x, y, 1.0f); // colors float r = (float)color.r / 255.0f; float g = (float)color.g / 255.0f; float b = (float)color.b / 255.0f; float a = (float)color.a / 255.0f; if (a != 255.0f && a != 0.0f) { glColor4f(r, g, b, a); } else { glColor3f(r, g, b); } // unbind textures glBindTexture(GL_TEXTURE_2D, 0); // we only want to draw lines glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // draw ! glBegin(GL_QUADS); // top left glTexCoord2d(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); // top right glTexCoord2d(1.0, 0.0f); glVertex2f(width, 0.0f); // bottom right glTexCoord2d(1.0f, 1.0f); glVertex2f(width, height); // bottom left glTexCoord2d(0.0f, 1.0f); glVertex2f(0.0f, height); glEnd(); return 0; } // outlined quad int renderLQuad(int x, int y, int width, int height, SDL_Color color) { // reset view glLoadIdentity(); // translate to a quad glTranslated(x, y, 1.0f); // colors float r = (float)color.r / 255.0f; float g = (float)color.g / 255.0f; float b = (float)color.b / 255.0f; glColor3f(r, g, b); // unbind textures glBindTexture(GL_TEXTURE_2D, 0); // we only want to draw lines glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // draw ! glBegin(GL_QUADS); // top left glTexCoord2d(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); // top right glTexCoord2d(1.0, 0.0f); glVertex2f(width, 0.0f); // bottom right glTexCoord2d(1.0f, 1.0f); glVertex2f(width, height); // bottom left glTexCoord2d(0.0f, 1.0f); glVertex2f(0.0f, height); glEnd(); return 0; } int renderTexture(GLuint texture, int x, int y, int width, int height) { // make sure we're rendering textures glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // bind our texture glColor3f(1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, texture); // reset view glLoadIdentity(); // translate to a quad glTranslated(x, y, 1.0f); // draw ! glBegin(GL_QUADS); // top left glTexCoord2d(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); // top right glTexCoord2d(1.0, 0.0f); glVertex2f(width, 0.0f); // bottom right glTexCoord2d(1.0f, 1.0f); glVertex2f(width, height); // bottom left glTexCoord2d(0.0f, 1.0f); glVertex2f(0.0f, height); glEnd(); return 0; }