Advertisement
Guest User

Untitled

a guest
Oct 18th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. void Window::Clear() {
  2. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  3. glClear(GL_COLOR_BUFFER_BIT);
  4. }
  5.  
  6. void Window::Update() {
  7. glFinish();
  8. SDL_GL_SwapWindow(m_window);
  9. }
  10.  
  11. void Texture::Load(const std::string &filename) {
  12. m_surface = IMG_Load(filename.c_str());
  13.  
  14. // Get texture height & width
  15. m_height = m_surface->h;
  16. m_width = m_surface->w;
  17.  
  18. glGenTextures(1, &m_textureId);
  19. glBindTexture(GL_TEXTURE_2D, m_textureId);
  20.  
  21. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  22. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  23.  
  24. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  25. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  26.  
  27. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_surface->w, m_surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_surface->pixels);
  28.  
  29. SDL_FreeSurface(m_surface);
  30. }
  31.  
  32. void Texture::Draw(const float &x, const float &y, bool blend) {
  33.  
  34. GLfloat vertexArray[] = { x, y, (float)m_width + x, y, (float)m_width + x, (float)m_height + y, x, (float)m_height + y };
  35. GLfloat textureVertexArray[] = {0, 1, 1, 1, 1, 0, 0, 0};
  36.  
  37. glEnable(GL_TEXTURE_2D);
  38.  
  39. glEnable(GL_BLEND);
  40. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  41.  
  42. glEnableClientState(GL_VERTEX_ARRAY);
  43. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  44.  
  45. glBindTexture(GL_TEXTURE_2D, m_textureId);
  46.  
  47. glVertexPointer(2, GL_FLOAT, 0, vertexArray);
  48. glTexCoordPointer(2, GL_FLOAT, 0, textureVertexArray);
  49.  
  50. glDrawArrays(GL_QUADS, 0, 4);
  51.  
  52. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  53. glDisableClientState(GL_VERTEX_ARRAY);
  54.  
  55. glDisable(GL_BLEND);
  56.  
  57. glDisable(GL_TEXTURE_2D);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement