Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. GLuint m_VAO;
  2. GLuint m_VBO;
  3. GLuint m_tex;
  4.  
  5. int m_image_width, m_image_height;
  6. unsigned char* m_image = nullptr;
  7.  
  8. std::vector<Vertex> m_vertices;
  9.  
  10. [...]
  11.  
  12. glGenTextures(1, &m_tex);
  13. glBindTexture( GL_TEXTURE_2D, m_tex );
  14.  
  15. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
  16. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
  17. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
  18. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  19.  
  20. m_image = SOIL_load_image( textureName.c_str(), &m_image_width, &m_image_height, 0, SOIL_LOAD_AUTO );
  21.  
  22. if( m_image == 0 )
  23. {
  24. std::cout << "ERROR. SOIL did not work correctly: " << SOIL_last_result() << std::endl;
  25. }
  26.  
  27. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_image_width, m_image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_image );
  28. glGenerateMipmap( GL_TEXTURE_2D );
  29.  
  30. SOIL_free_image_data( m_image );
  31. glBindTexture( GL_TEXTURE_2D, 0 );
  32.  
  33. glBindVertexArray( m_VAO );
  34. glEnableVertexAttribArray( 2 );
  35. glVertexAttribPointer( 2, 2, GL_FLOAT,GL_FALSE, sizeof( Vertex ), ( GLvoid* )offsetof( Vertex, texture ) );
  36. glBindVertexArray( 0 );
  37.  
  38. glBindTexture( GL_TEXTURE_2D, m_tex );
  39. glBindVertexArray( m_VAO );
  40. glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
  41. glBindVertexArray( 0 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement