Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Window::Clear() {
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- }
- void Window::Update() {
- glFinish();
- SDL_GL_SwapWindow(m_window);
- }
- void Texture::Load(const std::string &filename) {
- m_surface = IMG_Load(filename.c_str());
- // Get texture height & width
- m_height = m_surface->h;
- m_width = m_surface->w;
- glGenTextures(1, &m_textureId);
- glBindTexture(GL_TEXTURE_2D, m_textureId);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_surface->w, m_surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_surface->pixels);
- SDL_FreeSurface(m_surface);
- }
- void Texture::Draw(const float &x, const float &y, bool blend) {
- GLfloat vertexArray[] = { x, y, (float)m_width + x, y, (float)m_width + x, (float)m_height + y, x, (float)m_height + y };
- GLfloat textureVertexArray[] = {0, 1, 1, 1, 1, 0, 0, 0};
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindTexture(GL_TEXTURE_2D, m_textureId);
- glVertexPointer(2, GL_FLOAT, 0, vertexArray);
- glTexCoordPointer(2, GL_FLOAT, 0, textureVertexArray);
- glDrawArrays(GL_QUADS, 0, 4);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisable(GL_BLEND);
- glDisable(GL_TEXTURE_2D);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement