Graphics Reference
In-Depth Information
Table 9-10
Valid Depth Sized Internal Format Combinations for glTexImage2D
internalFormat
format
type
GL_DEPTH_COMPONENT16
GL_DEPTH_COMPONENT
GL_UNSIGNED_SHORT
GL_DEPTH_COMPONENT16
GL_DEPTH_COMPONENT
GL_UNSIGNED_INT
GL_DEPTH_COMPONENT24
GL_DEPTH_COMPONENT
GL_UNSIGNED_INT
GL_DEPTH_COMPONENT32F GL_DEPTH_COMPONENT
GL_FLOAT
GL_DEPTH24_STENCIL8
GL_DEPTH_STENCIL
GL_UNSIGNED_INT_24_8
GL_DEPTH32F_STENCIL8
GL_DEPTH_STENCIL
GL_FLOAT_32_UNSIGNED_
INT_24_8_REV
Using Textures in a Shader
Now that we have covered the basics of setting up texturing, let's look at
some sample shader code. The vertex-fragment shader pair in Example 9-3
from the Simple_Texture2D sample demonstrates the basics of how 2D
texturing is done in a shader.
Example 9-3
Vertex and Fragment Shaders for Performing 2D Texturing
// Vertex shader
#version 300 es
layout(location = 0) in vec4 a_position;
layout(location = 1) in vec2 a_texCoord;
out vec2 v_texCoord;
void main()
{
gl_Position = a_position;
v_texCoord = a_texCoord;
}
// Fragment shader
#version 300 es
precision mediump float;
in vec2 v_texCoord;
layout(location = 0) out vec4 outColor;
uniform sampler2D s_texture;
void main()
{
outColor = texture( s_texture, v_texCoord );
}
 
 
 
Search WWH ::




Custom Search