opengl. textures bind textures similar to binding vbo’s create a texture for each object ...

8
TEXTURES OpenGL

Upload: britney-williams

Post on 23-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

TEXTURESOpenGL

Page 2: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

Textures

Bind Textures similar to binding VBO’s Create a texture for each object Generate the texture similar how you

generate a VBO bufferGLuint textglGenTextures(1, &text)

Page 3: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

Update Vertex Struct

struct Vertex { GLfloat position[3]; GLfloat uv[2]; };

Page 4: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

Prepare Shader

Glint texAttrib = glGetAttribLocation(shaderProgram, “texcoord”);

glEnableVertexAttribArray(texAttrib); glVertexAttribPointer(texAttrib, 2,

GL_FLOAT, GL_FALSE, sizeof(Vertex),(void*)offsetOf(Vertex,uv))

Page 5: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

Assimp Textures

When looping through each face for it’s vertices you will need to check the mesh for texture coordinates.mesh->HasTextureCoords(0)aiVector3D textureCoord = mesh-

>mTextureCoords[0][face.mIndices[k]]vert.uv[0] = textureCoord.x;vert.uv[1] = textureCoord.y

Page 6: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

Bind Texture To Image

Set Active Texture for ShaderglActiveTexture(GL_TEXTURE0)

BindingglTexImage2D(GL_TEXTURE_2D, 0,

GL_RGB, imgWidth, imgHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, image )

“image” is an array of pixels you obtain from your image loader

Page 7: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

Image Libraries

ImageMagick++ FreeImagePlus Many more… Specify which one you used in your

readme!

Page 8: OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer

References

https://www.open.gl/texturesProvides information on shaders which you

will need