Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GLuint m_VAO;
- GLuint m_VBO;
- GLuint m_tex;
- int m_image_width, m_image_height;
- unsigned char* m_image = nullptr;
- std::vector<Vertex> m_vertices;
- [...]
- glGenTextures(1, &m_tex);
- glBindTexture( GL_TEXTURE_2D, m_tex );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- m_image = SOIL_load_image( textureName.c_str(), &m_image_width, &m_image_height, 0, SOIL_LOAD_AUTO );
- if( m_image == 0 )
- {
- std::cout << "ERROR. SOIL did not work correctly: " << SOIL_last_result() << std::endl;
- }
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_image_width, m_image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_image );
- glGenerateMipmap( GL_TEXTURE_2D );
- SOIL_free_image_data( m_image );
- glBindTexture( GL_TEXTURE_2D, 0 );
- glBindVertexArray( m_VAO );
- glEnableVertexAttribArray( 2 );
- glVertexAttribPointer( 2, 2, GL_FLOAT,GL_FALSE, sizeof( Vertex ), ( GLvoid* )offsetof( Vertex, texture ) );
- glBindVertexArray( 0 );
- glBindTexture( GL_TEXTURE_2D, m_tex );
- glBindVertexArray( m_VAO );
- glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
- glBindVertexArray( 0 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement