本文整理汇总了C++中VBObject类的典型用法代码示例。如果您正苦于以下问题:C++ VBObject类的具体用法?C++ VBObject怎么用?C++ VBObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VBObject类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Display
void FurApplication::Display(bool auto_redraw)
{
float t = float(GetTickCount() & 0x3FFF) / float(0x3FFF);
static const vmath::vec3 X(1.0f, 0.0f, 0.0f);
static const vmath::vec3 Y(0.0f, 1.0f, 0.0f);
static const vmath::vec3 Z(0.0f, 0.0f, 1.0f);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
vmath::mat4 p(vmath::frustum(-1.0f, 1.0f, aspect, -aspect, 1.0f, 5000.0f));
vmath::mat4 m;
m = vmath::mat4(vmath::translate(0.0f,
0.0f,
/* 100.0f * sinf(6.28318531f * t)*/ - 150.0f) *
//vmath::rotation(360.0f * t, X) *
vmath::rotate(360.0f * t * 1.0f, Y) *
vmath::rotate(180.0f, Z) *
vmath::translate(0.0f, -80.0f, 0.0f));
glUseProgram(base_prog);
glUniformMatrix4fv(base_model_matrix_pos, 1, GL_FALSE, m[0]);
glUniformMatrix4fv(base_projection_matrix_pos, 1, GL_FALSE, p);
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
object.Render();
glUseProgram(fur_prog);
glUniformMatrix4fv(fur_model_matrix_pos, 1, GL_FALSE, m[0]);
glUniformMatrix4fv(fur_projection_matrix_pos, 1, GL_FALSE, p);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
object.Render();
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
base::Display();
}
开发者ID:tantantzp,项目名称:GLredbook_code,代码行数:55,代码来源:ch10_fur.cpp
示例2: DrawScene
void ShadowMapExample::DrawScene(bool depth_only)
{
// Set material properties for the object
if (!depth_only)
{
glUniform3fv(render_scene_uniforms.material_ambient, 1, vec3(0.1f, 0.0f, 0.2f));
glUniform3fv(render_scene_uniforms.material_diffuse, 1, vec3(0.3f, 0.2f, 0.8f));
glUniform3fv(render_scene_uniforms.material_specular, 1, vec3(1.0f, 1.0f, 1.0f));
glUniform1f(render_scene_uniforms.material_specular_power, 25.0f);
}
// Draw the object
object.Render();
// Set material properties for the ground
if (!depth_only)
{
glUniform3fv(render_scene_uniforms.material_ambient, 1, vec3(0.1f, 0.1f, 0.1f));
glUniform3fv(render_scene_uniforms.material_diffuse, 1, vec3(0.1f, 0.5f, 0.1f));
glUniform3fv(render_scene_uniforms.material_specular, 1, vec3(0.1f, 0.1f, 0.1f));
glUniform1f(render_scene_uniforms.material_specular_power, 3.0f);
}
// Draw the ground
glBindVertexArray(ground_vao);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindVertexArray(0);
}
开发者ID:cemegginson,项目名称:opengl_redbook,代码行数:28,代码来源:ch04_shadowmap.cpp
示例3: Display
void LightingExample::Display(bool auto_redraw)
{
float time = 0.5f; // float(GetTickCount() & 0xFFFF) / float(0xFFFF);
vmath::mat4 mv_matrix = vmath::translate(0.0f, 0.0f, -4.0f) *
vmath::rotate(987.0f * time * 3.14159f, vmath::vec3(0.0f, 0.0f, 1.0f)) *
vmath::rotate(1234.0f * time * 3.14159f, vmath::vec3(1.0f, 0.0f, 0.0f));
vmath::mat4 prj_matrix = vmath::perspective(60.0f, 1.333f, 0.1f, 1000.0f);
glUseProgram(render_prog);
glUniformMatrix4fv(mv_mat_loc, 1, GL_FALSE, mv_matrix);
glUniformMatrix4fv(prj_mat_loc, 1, GL_FALSE, prj_matrix);
// Clear, select the rendering program and draw a full screen quad
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
object.Render();
base::Display();
}
开发者ID:cemegginson,项目名称:opengl_redbook,代码行数:25,代码来源:ch08_lightmodels.cpp
示例4: Initialize
void FurApplication::Initialize(const char * title)
{
base::Initialize(title);
static ShaderInfo shader_info[] =
{
{ GL_VERTEX_SHADER, "base_vs.glsl" },
{ GL_FRAGMENT_SHADER, "base_fs.glsl" },
{ GL_NONE, NULL }
};
base_prog = LoadShaders(shader_info);
glUseProgram(base_prog);
base_model_matrix_pos = glGetUniformLocation(base_prog, "model_matrix");
base_projection_matrix_pos = glGetUniformLocation(base_prog, "projection_matrix");
static ShaderInfo shader_info2[] =
{
{ GL_VERTEX_SHADER, "fur_vs.glsl" },
{ GL_GEOMETRY_SHADER, "fur_gs.glsl" },
{ GL_FRAGMENT_SHADER, "fur_fs.glsl" },
{ GL_NONE, NULL }
};
fur_prog = LoadShaders(shader_info2);
glUseProgram(fur_prog);
fur_model_matrix_pos = glGetUniformLocation(fur_prog, "model_matrix");
fur_projection_matrix_pos = glGetUniformLocation(fur_prog, "projection_matrix");
glGenTextures(1, &fur_texture);
unsigned char * tex = (unsigned char *)malloc(1024 * 1024 * 4);
memset(tex, 0, 1024 * 1024 * 4);
int n, m;
for (n = 0; n < 256; n++)
{
for (m = 0; m < 1270; m++)
{
int x = rand() & 0x3FF;
int y = rand() & 0x3FF;
tex[(y * 1024 + x) * 4 + 0] = n;//(rand() & 0x3F) + 0xC0;
tex[(y * 1024 + x) * 4 + 1] = n;//(rand() & 0x3F) + 0xC0;
tex[(y * 1024 + x) * 4 + 2] = n;//(rand() & 0x3F) + 0xC0;
tex[(y * 1024 + x) * 4 + 3] = n;
}
}
glBindTexture(GL_TEXTURE_2D, fur_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
free(tex);
//object.LoadFromVBM("F:/tzpRepository/opengl/oglpg-8th-edition/media/unit_cube.vbm", 0, 1, 2);
object.LoadFromVBM("F:/tzpRepository/opengl/oglpg-8th-edition/media/ninja.vbm", 0, 1, 2);
}
开发者ID:tantantzp,项目名称:GLredbook_code,代码行数:58,代码来源:ch10_fur.cpp
示例5: init_buffer
void ImageApp::init_buffer()
{
render_scene_prog = -1;
// Create palette texture
glGenBuffers(1, &image_palette_buffer);
glBindBuffer(GL_TEXTURE_BUFFER, image_palette_buffer);
glBufferData(GL_TEXTURE_BUFFER, 256 * 4 * sizeof(float), NULL, GL_STATIC_DRAW);
glGenTextures(1, &image_palette_texture);
glBindTexture(GL_TEXTURE_BUFFER, image_palette_texture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, image_palette_buffer);
vmath::vec4 * data = (vmath::vec4 *)glMapBuffer(GL_TEXTURE_BUFFER, GL_WRITE_ONLY);
for (int i = 0; i < 256; i++)
{
data[i] = vmath::vec4((float)i);
}
glUnmapBuffer(GL_TEXTURE_BUFFER);
// Create overdraw counter texture
glGenTextures(1, &overdraw_count_buffer);
glBindTexture(GL_TEXTURE_2D, overdraw_count_buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, MAX_FRAMEBUFFER_WIDTH, MAX_FRAMEBUFFER_HEIGHT, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
// Create buffer for clearing the head pointer texture
glGenBuffers(1, &overdraw_count_clear_buffer);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, overdraw_count_clear_buffer);
glBufferData(GL_PIXEL_UNPACK_BUFFER, MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT * sizeof(GLuint), NULL, GL_STATIC_DRAW);
data = (vmath::vec4 *)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memset(data, 0x00, MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT * sizeof(GLuint));
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
// Create VAO containing quad for the final blit
glGenVertexArrays(1, &quad_vao);
glBindVertexArray(quad_vao);
static const GLfloat quad_verts[] =
{
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
};
glGenBuffers(1, &quad_vbo);
glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(quad_verts), quad_verts, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(0);
glClearDepth(1.0f);
object.LoadFromVBM("../../../media/objects/unit_pipe.vbm", 0, 1, 2);
}
开发者ID:jordonwu,项目名称:OpenGL-Redbook,代码行数:58,代码来源:ch11-02-OverDrawCount.cpp
示例6: Display
void InstancingExample::Display(bool auto_redraw)
{
float t = float(GetTickCount() & 0x3FFF) / float(0x3FFF);
static float q = 0.0f;
static const vec3 X(1.0f, 0.0f, 0.0f);
static const vec3 Y(0.0f, 1.0f, 0.0f);
static const vec3 Z(0.0f, 0.0f, 1.0f);
int n;
// Clear
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Setup
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
// Bind the weight VBO and change its data
glBindBuffer(GL_ARRAY_BUFFER, model_matrix_buffer);
// Set model matrices for each instance
mat4 * matrices = (mat4 *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
for (n = 0; n < INSTANCE_COUNT; n++)
{
float a = 50.0f * float(n) / 4.0f;
float b = 50.0f * float(n) / 5.0f;
float c = 50.0f * float(n) / 6.0f;
matrices[n] = rotate(a + t * 360.0f, 1.0f, 0.0f, 0.0f) *
rotate(b + t * 360.0f, 0.0f, 1.0f, 0.0f) *
rotate(c + t * 360.0f, 0.0f, 0.0f, 1.0f) *
translate(10.0f + a, 40.0f + b, 50.0f + c);
}
glUnmapBuffer(GL_ARRAY_BUFFER);
// Activate instancing program
glUseProgram(render_prog);
// Set up the view and projection matrices
mat4 view_matrix(translate(0.0f, 0.0f, -1500.0f) * rotate(t * 360.0f * 2.0f, 0.0f, 1.0f, 0.0f));
mat4 projection_matrix(frustum(-1.0f, 1.0f, -aspect, aspect, 1.0f, 5000.0f));
glUniformMatrix4fv(view_matrix_loc, 1, GL_FALSE, view_matrix);
glUniformMatrix4fv(projection_matrix_loc, 1, GL_FALSE, projection_matrix);
// Render INSTANCE_COUNT objects
object.Render(0, INSTANCE_COUNT);
lookat(vec3(0.0f, 0.0f, 0.0f), vec3(1.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
base::Display();
}
开发者ID:pkxpp,项目名称:github_opengl,代码行数:54,代码来源:ch03_instancing2.cpp
示例7: Display
void CubeMapExample::Display(bool auto_redraw)
{
static const unsigned int start_time = GetTickCount();
float t = float((GetTickCount() - start_time)) / float(0x3FFF);
static const vmath::vec3 X(1.0f, 0.0f, 0.0f);
static const vmath::vec3 Y(0.0f, 1.0f, 0.0f);
static const vmath::vec3 Z(0.0f, 0.0f, 1.0f);
vmath::mat4 tc_matrix(vmath::mat4::identity());
glClearColor(0.0f, 0.25f, 0.3f, 1.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDisable(GL_CULL_FACE);
//调用天空盒映射着色器程序
glUseProgram(skybox_prog);
//GL_TEXTURE_CUBE_MAP_SEAMLESS启用无缝立方体映射滤波,避免立方体映射相邻边之间的缝
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
tc_matrix = vmath::rotate(80.0f * 3.0f * t, Y);// * vmath::rotate(22.0f, Z);
tc_matrix = vmath::perspective(35.0f, 1.0f / aspect, 0.1f, 100.0f) * tc_matrix;
glUniformMatrix4fv(skybox_rotate_loc, 1, GL_FALSE, tc_matrix);
glBindVertexArray(vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cube_element_buffer);
//绘制天空盒,完成立方体映射
glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_SHORT, NULL);
glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_SHORT, BUFFER_OFFSET(8 * sizeof(GLushort)));
//调用环境映射着色器程序
glUseProgram(object_prog);
tc_matrix = vmath::translate(vmath::vec3(0.0f, 0.0f, -4.0f)) *
vmath::rotate(80.0f * 3.0f * t, Y) * vmath::rotate(70.0f * 3.0f * t, Z);
glUniformMatrix4fv(object_mat_mv_loc, 1, GL_FALSE, tc_matrix);
tc_matrix = vmath::perspective(35.0f, 1.0f / aspect, 0.1f, 100.0f) * tc_matrix;
glUniformMatrix4fv(object_mat_mvp_loc, 1, GL_FALSE, tc_matrix);
glClear(GL_DEPTH_BUFFER_BIT);
//绘制物体,完成环境映射
object.Render();
base::Display();
}
开发者ID:ZYMing,项目名称:OpenGL-Shader,代码行数:51,代码来源:ch06_cube_map.cpp
示例8: Display
void OverdrawCountExample::Display(bool auto_redraw)
{
float t;
unsigned int current_time = GetTickCount();
t = (float)(current_time & 0xFFFFF) / (float)0x3FFF;
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Clear output image
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, overdraw_count_clear_buffer);
glBindTexture(GL_TEXTURE_2D, overdraw_count_buffer);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, current_width, current_height, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
// Bind output image for read-write
glBindImageTexture(0, overdraw_count_buffer, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI);
// Render
glUseProgram(render_scene_prog);
vmath::mat4 model_matrix = vmath::translate(0.0f, 0.0f, -20.0f) *
vmath::rotate(t * 360.0f, 0.0f, 0.0f, 1.0f) *
vmath::rotate(t * 435.0f, 0.0f, 1.0f, 0.0f) *
vmath::rotate(t * 275.0f, 1.0f, 0.0f, 0.0f);
vmath::mat4 view_matrix = vmath::mat4::identity();
vmath::mat4 projection_matrix = vmath::frustum(-1.0f, 1.0f, aspect, -aspect, 1.0f, 40.f);
glUniformMatrix4fv(render_scene_uniforms.model_matrix, 1, GL_FALSE, model_matrix);
glUniformMatrix4fv(render_scene_uniforms.view_matrix, 1, GL_FALSE, view_matrix);
glUniformMatrix4fv(render_scene_uniforms.projection_matrix, 1, GL_FALSE, projection_matrix);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
object.Render(0, 8 * 8 * 8);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glBindVertexArray(quad_vao);
glUseProgram(resolve_program);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Done
base::Display();
}
开发者ID:cemegginson,项目名称:opengl_redbook,代码行数:50,代码来源:ch11_overdrawcount.cpp
示例9: Init
void Init(void)
{
ShaderInfo shaders[] = {
{ GL_VERTEX_SHADER, "light_model.vert" },
{ GL_FRAGMENT_SHADER, "light_model.frag" },
{ GL_NONE, NULL}
};
light_prog = LoadShaders(shaders);
model_mat_loc = glGetUniformLocation(light_prog, "model_matrix");
proj_mat_loc = glGetUniformLocation(light_prog, "proj_matrix");
color_ambient_loc = glGetUniformLocation(light_prog, "color_ambient");
color_diffuse_loc = glGetUniformLocation(light_prog, "color_diffuse");
color_specular_loc = glGetUniformLocation(light_prog, "color_specular");
shininess_loc = glGetUniformLocation(light_prog, "shininess");
light_pos_loc = glGetUniformLocation(light_prog, "light_position");
object.LoadFromVBM("../../media/unit_torus.vbm", 0, 1, 2);
}
开发者ID:ZYMing,项目名称:OpenGL-Shader,代码行数:20,代码来源:light_model.cpp
示例10: DisplayFunc
void DisplayFunc(void)
{
float time = float(GetTickCount() & 0xFFFF) / float(0xFFFF);
vmath::mat4 model_matrix = vmath::translate(0.0f, 0.0f, -4.0f) *
vmath::rotate(987.0f * time * 3.141592f, vmath::vec3(0.0f, 0.0f, 1.0f)) *
vmath::rotate(1234.0f *time * 3.141592f, vmath::vec3(1.0f, 0.0f, 0.0f));
vmath::mat4 proj_matrix = vmath::perspective(60.0f, 1.333, 0.1f, 1000.0f);
glUseProgram(light_prog);
glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, model_matrix);
glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, proj_matrix);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
object.Render();
glutPostRedisplay();
}
开发者ID:ZYMing,项目名称:OpenGL-Shader,代码行数:24,代码来源:light_model.cpp
示例11: Initialize
void InstancingExample::Initialize(const char * title)
{
int n;
base::Initialize(title);
// Create the program for rendering the model
render_prog = glCreateProgram();
// This is the rendering vertex shader
static const char render_vs[] =
"#version 330\n"
"\n"
"// 'position' and 'normal' are regular vertex attributes\n"
"layout (location = 0) in vec4 position;\n"
"layout (location = 1) in vec3 normal;\n"
"\n"
"// Color is a per-instance attribute\n"
"layout (location = 2) in vec4 color;\n"
"\n"
"// model_matrix will be used as a per-instance transformation\n"
"// matrix. Note that a mat4 consumes 4 consecutive locations, so\n"
"// this will actually sit in locations, 3, 4, 5, and 6.\n"
"layout (location = 3) in mat4 model_matrix;\n"
"\n"
"// The view matrix and the projection matrix are constant across a draw\n"
"uniform mat4 view_matrix;\n"
"uniform mat4 projection_matrix;\n"
"\n"
"// The output of the vertex shader (matched to the fragment shader)\n"
"out VERTEX\n"
"{\n"
" vec3 normal;\n"
" vec4 color;\n"
"} vertex;\n"
"\n"
"// Ok, go!\n"
"void main(void)\n"
"{\n"
" // Construct a model-view matrix from the uniform view matrix\n"
" // and the per-instance model matrix.\n"
" mat4 model_view_matrix = view_matrix * model_matrix;\n"
"\n"
" // Transform position by the model-view matrix, then by the\n"
" // projection matrix.\n"
" gl_Position = projection_matrix * (model_view_matrix * position);\n"
" // Transform the normal by the upper-left-3x3-submatrix of the\n"
" // model-view matrix\n"
" vertex.normal = mat3(model_view_matrix) * normal;\n"
" // Pass the per-instance color through to the fragment shader.\n"
" vertex.color = color;\n"
"}\n";
// Simple fragment shader
static const char render_fs[] =
"#version 330\n"
"\n"
"layout (location = 0) out vec4 color;\n"
"\n"
"in VERTEX\n"
"{\n"
" vec3 normal;\n"
" vec4 color;\n"
"} vertex;\n"
"\n"
"void main(void)\n"
"{\n"
" color = vertex.color * (0.1 + abs(vertex.normal.z)) + vec4(0.8, 0.9, 0.7, 1.0) * pow(abs(vertex.normal.z), 40.0);\n"
"}\n";
// Compile and link like normal
vglAttachShaderSource(render_prog, GL_VERTEX_SHADER, render_vs);
vglAttachShaderSource(render_prog, GL_FRAGMENT_SHADER, render_fs);
glLinkProgram(render_prog);
glUseProgram(render_prog);
// Get the location of the projetion_matrix uniform
view_matrix_loc = glGetUniformLocation(render_prog, "view_matrix");
projection_matrix_loc = glGetUniformLocation(render_prog, "projection_matrix");
// Load the object
object.LoadFromVBM("../../media/armadillo_low.vbm", 0, 1, 2);
// Bind its vertex array object so that we can append the instanced attributes
object.BindVertexArray();
// Get the locations of the vertex attributes in 'prog', which is the
// (linked) program object that we're going to be rendering with. Note
// that this isn't really necessary because we specified locations for
// all the attributes in our vertex shader. This code could be made
// more concise by assuming the vertex attributes are where we asked
// the compiler to put them.
int position_loc = glGetAttribLocation(render_prog, "position");
int normal_loc = glGetAttribLocation(render_prog, "normal");
int color_loc = glGetAttribLocation(render_prog, "color");
int matrix_loc = glGetAttribLocation(render_prog, "model_matrix");
// Configure the regular vertex attribute arrays - position and color.
/*
//.........这里部分代码省略.........
开发者ID:pkxpp,项目名称:github_opengl,代码行数:101,代码来源:ch03_instancing2.cpp
示例12: Initialize
void ShadowMapExample::Initialize(const char * title)
{
base::Initialize(title);
// Create the program for rendering the scene from the light's POV.
glCreateProgram();
ShaderInfo light_shaders[] =
{
{ GL_VERTEX_SHADER, "shadowmap_shadow.vs.glsl" },
{ GL_FRAGMENT_SHADER, "shadowmap_shadow.fs.glsl" },
{ GL_NONE }
};
render_light_prog = LoadShaders(light_shaders);
// Get the location of the projetion_matrix uniform
render_light_uniforms.model_view_projection_matrix = glGetUniformLocation(render_light_prog, "model_view_projection_matrix");
// Create the program for rendering the scene from the viewer's position
ShaderInfo scene_shaders[] =
{
{ GL_VERTEX_SHADER, "shadowmap_scene.vs.glsl" },
{ GL_FRAGMENT_SHADER, "shadowmap_scene.fs.glsl" },
{ GL_NONE }
};
render_scene_prog = LoadShaders(scene_shaders);
// Get the locations of all the uniforms in the program
render_scene_uniforms.model_matrix = glGetUniformLocation(render_scene_prog, "model_matrix");
render_scene_uniforms.view_matrix = glGetUniformLocation(render_scene_prog, "view_matrix");
render_scene_uniforms.projection_matrix = glGetUniformLocation(render_scene_prog, "projection_matrix");
render_scene_uniforms.shadow_matrix = glGetUniformLocation(render_scene_prog, "shadow_matrix");
render_scene_uniforms.light_position = glGetUniformLocation(render_scene_prog, "light_position");
render_scene_uniforms.material_ambient = glGetUniformLocation(render_scene_prog, "material_ambient");
render_scene_uniforms.material_diffuse = glGetUniformLocation(render_scene_prog, "material_diffuse");
render_scene_uniforms.material_specular = glGetUniformLocation(render_scene_prog, "material_specular");
render_scene_uniforms.material_specular_power = glGetUniformLocation(render_scene_prog, "material_specular_power");
// Set the depth texture uniform to unit 0
glUseProgram(render_scene_prog);
glUniform1i(glGetUniformLocation(render_scene_prog, "depth_texture"), 0);
// Create a depth texture
glGenTextures(1, &depth_texture);
glBindTexture(GL_TEXTURE_2D, depth_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
// Create FBO to render depth into
glGenFramebuffers(1, &depth_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, depth_fbo);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, depth_texture, 0);
glDrawBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Upload geometry for the ground plane
static const float ground_vertices[] =
{
-500.0f, -50.0f, -500.0f, 1.0f,
-500.0f, -50.0f, 500.0f, 1.0f,
500.0f, -50.0f, 500.0f, 1.0f,
500.0f, -50.0f, -500.0f, 1.0f,
};
static const float ground_normals[] =
{
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f
};
glGenVertexArrays(1, &ground_vao);
glGenBuffers(1, &ground_vbo);
glBindVertexArray(ground_vao);
glBindBuffer(GL_ARRAY_BUFFER, ground_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(ground_vertices) + sizeof(ground_normals), NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ground_vertices), ground_vertices);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(ground_vertices), sizeof(ground_normals), ground_normals);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)sizeof(ground_vertices));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
// Load the object
object.LoadFromVBM("C:/Vermilion-Book/trunk/Code/media/armadillo_low.vbm", 0, 1, 2);
}
开发者ID:cemegginson,项目名称:opengl_redbook,代码行数:97,代码来源:ch04_shadowmap.cpp
示例13: Initialize
void FurApplication::Initialize(const char * title)
{
base::Initialize(title);
base_prog = glCreateProgram();
static const char base_vs_source[] =
"#version 410\n"
"\n"
"layout (location = 0) in vec4 position_in;\n"
"layout (location = 1) in vec3 normal_in;\n"
"layout (location = 2) in vec2 texcoord_in;\n"
"\n"
"uniform mat4 model_matrix;\n"
"uniform mat4 projection_matrix;\n"
"\n"
"out VS_FS_VERTEX\n"
"{\n"
" vec3 normal;\n"
"} vertex_out;\n"
"\n"
"void main(void)\n"
"{\n"
" vertex_out.normal = normal_in;\n"
" gl_Position = projection_matrix * (model_matrix * position_in);\n"
"}\n";
static const char base_fs_source[] =
"#version 410\n"
"\n"
"layout (location = 0) out vec4 color;\n"
"\n"
"in VS_FS_VERTEX\n"
"{\n"
" vec3 normal;\n"
"} vertex_in;\n"
"\n"
"void main(void)\n"
"{\n"
" vec3 normal = vertex_in.normal;\n"
" color = vec4(0.2, 0.1, 0.5, 1.0) * (0.2 + pow(abs(normal.z), 4.0)) + vec4(0.8, 0.8, 0.8, 0.0) * pow(abs(normal.z), 137.0);\n"
"}\n";
vglAttachShaderSource(base_prog, GL_VERTEX_SHADER, base_vs_source);
vglAttachShaderSource(base_prog, GL_FRAGMENT_SHADER, base_fs_source);
glLinkProgram(base_prog);
glUseProgram(base_prog);
base_model_matrix_pos = glGetUniformLocation(base_prog, "model_matrix");
base_projection_matrix_pos = glGetUniformLocation(base_prog, "projection_matrix");
fur_prog = glCreateProgram();
static const char fur_vs_source[] =
"#version 410\n"
"\n"
"layout (location = 0) in vec4 position_in;\n"
"layout (location = 1) in vec3 normal_in;\n"
"layout (location = 2) in vec2 texcoord_in;\n"
"\n"
"out VS_GS_VERTEX\n"
"{\n"
" vec3 normal;\n"
" vec2 tex_coord;\n"
"} vertex_out;\n"
"\n"
"void main(void)\n"
"{\n"
" vertex_out.normal = normal_in;\n"
" vertex_out.tex_coord = texcoord_in;\n"
" gl_Position = position_in;\n"
"}\n";
static const char fur_gs_source[] =
"#version 410\n"
"\n"
"layout (triangles) in;\n"
"layout (triangle_strip, max_vertices = 240) out;\n"
"\n"
"uniform mat4 model_matrix;\n"
"uniform mat4 projection_matrix;\n"
"\n"
"uniform int fur_layers = 30;\n"
"uniform float fur_depth = 5.0;\n"
"\n"
"in VS_GS_VERTEX\n"
"{\n"
" vec3 normal;\n"
" vec2 tex_coord;\n"
"} vertex_in[];\n"
"\n"
"out GS_FS_VERTEX\n"
"{\n"
" vec3 normal;\n"
" vec2 tex_coord;\n"
" flat float fur_strength;\n"
"} vertex_out;\n"
"\n"
"void main(void)\n"
//.........这里部分代码省略.........
开发者ID:cemegginson,项目名称:opengl_redbook,代码行数:101,代码来源:ch10_fur.cpp
示例14: Initialize
void ViewportArrayApplication::Initialize(const char * title)
{
int i;
base::Initialize(title);
glGenTransformFeedbacks(1, &xfb);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, xfb);
sort_prog = glCreateProgram();
static const char sort_vs_source[] =
"#version 410\n"
"\n"
"uniform mat4 model_matrix;\n"
"\n"
"layout (location = 0) in vec4 position;\n"
"layout (location = 1) in vec3 normal;\n"
"\n"
"out vec3 vs_normal;\n"
"\n"
"void main(void)\n"
"{\n"
" vs_normal = (model_matrix * vec4(normal, 0.0)).xyz;\n"
" gl_Position = model_matrix * position;\n"
"}\n";
static const char sort_gs_source[] =
"#version 410\n"
"\n"
"layout (triangles) in;\n"
"layout (points, max_vertices = 3) out;\n"
"\n"
"uniform mat4 projection_matrix;\n"
"\n"
"in vec3 vs_normal[];\n"
"\n"
"layout (stream = 0) out vec4 rf_position;\n"
"layout (stream = 0) out vec3 rf_normal;\n"
"\n"
"layout (stream = 1) out vec4 lf_position;\n"
"layout (stream = 1) out vec3 lf_normal;\n"
"\n"
"void main(void)\n"
"{\n"
" vec4 A = gl_in[0].gl_Position;\n"
" vec4 B = gl_in[1].gl_Position;\n"
" vec4 C = gl_in[2].gl_Position;\n"
" vec3 AB = (B - A).xyz;\n"
" vec3 AC = (C - A).xyz;\n"
" vec3 face_normal = cross(AB, AC);\n"
" int i;\n"
"\n"
" if (face_normal.x < 0.0)\n"
" {\n"
" for (i = 0; i < gl_in.length(); i++)\n"
" {\n"
" rf_position = projection_matrix * (gl_in[i].gl_Position - vec4(30.0, 0.0, 0.0, 0.0));\n"
" rf_normal = vs_normal[i];\n"
" EmitStreamVertex(0);\n"
" }\n"
" EndStreamPrimitive(0);\n"
" }\n"
" else\n"
" {\n"
" for (i = 0; i < gl_in.length(); i++)\n"
" {\n"
" lf_position = projection_matrix * (gl_in[i].gl_Position + vec4(30.0, 0.0, 0.0, 0.0));\n"
" lf_normal = vs_normal[i];\n"
" EmitStreamVertex(1);\n"
" }\n"
" EndStreamPrimitive(1);\n"
" }\n"
"}\n";
vglAttachShaderSource(sort_prog, GL_VERTEX_SHADER, sort_vs_source);
vglAttachShaderSource(sort_prog, GL_GEOMETRY_SHADER, sort_gs_source);
static const char * varyings[] =
{
"rf_position", "rf_normal",
"gl_NextBuffer",
"lf_position", "lf_normal"
};
glTransformFeedbackVaryings(sort_prog, 5, varyings, GL_INTERLEAVED_ATTRIBS);
glLinkProgram(sort_prog);
glUseProgram(sort_prog);
model_matrix_pos = glGetUniformLocation(sort_prog, "model_matrix");
projection_matrix_pos = glGetUniformLocation(sort_prog, "projection_matrix");
glGenVertexArrays(2, vao);
glGenBuffers(2, vbo);
for (i = 0; i < 2; i++)
{
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, vbo[i]);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 1024 * 1024 * sizeof(GLfloat), NULL, GL_DYNAMIC_COPY);
//.........这里部分代码省略.........
开发者ID:cemegginson,项目名称:opengl_redbook,代码行数:101,代码来源:ch10_draw_xfb.cpp
示例15: Display
void ViewportArrayApplication::Display(bool auto_redraw)
{
float t = float(GetTickCount() & 0x3FFF) / float(0x3FFF);
static const vmath::vec3 X(1.0f, 0.0f, 0.0f);
static const vmath::vec3 Y(0.0f, 1.0f, 0.0f);
static const vmath::vec3 Z(0.0f, 0.0f, 1.0f);
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(sort_prog);
vmath::mat4 p(vmath::frustum(-1.0f, 1.0f, aspect, -aspect, 1.0f, 5000.0f));
vmath::mat4 m;
m = vmath::mat4(vmath::translate(0.0f,
0.0f,
100.0f * sinf(6.28318531f * t) - 230.0f) *
vmath::rotate(360.0f * t, X) *
vmath::rotate(360.0f * t * 2.0f, Y) *
vmath::rotate(360.0f * t * 5.0f, Z) *
vmath::translate(0.0f, -80.0f, 0.0f));
glUniformMatrix4fv(model_matrix_pos, 1, GL_FALSE, m[0]);
glUniformMatrix4fv(projection_matrix_pos, 1, GL_FALSE, p);
glEnable(GL_RASTERIZER_DISCARD);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, xfb);
glBeginTransformFeedback(GL_POINTS);
object.Render();
glEndTransformFeedback();
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
glDisable(GL_RASTERIZER_DISCARD);
static const vmath::vec4 colors[2] =
{
vmath::vec4(0.8f, 0.8f, 0.9f, 0.5f),
vmath::vec4(0.3f, 1.0f, 0.3f, 0.8f)
};
glUseProgram(render_prog);
glUniform4fv(0, 1, colors[0]);
glBindVertexArray(vao[0]);
glDrawTransformFeedbackStream(GL_TRIANGLES, xfb, 0);
glUniform4fv(0, 1, colors[1]);
glBindVertexArray(vao[1]);
glDrawTransformFeedbackStream(GL_TRIANGLES, xfb, 1);
base::Display();
}
开发者ID:cemegginson,项目名称:opengl_redbook,代码行数:61,代码来源:ch10_draw_xfb.cpp
示例16: Initialize
void CubeMapExample::Initialize(const char * title)
{
base::Initialize(title);
skybox_prog = glCreateProgram();
static const char skybox_shader_vs[] =
"#version 330 core\n"
"\n"
"layout (location = 0) in vec3 in_position;\n"
"\n"
"out vec3 tex_coord;\n"
"\n"
"uniform mat4 tc_rotate;\n"
"\n"
"void main(void)\n"
"{\n"
" gl_Position = tc_rotate * vec4(in_position, 1.0);\n"
" tex_coord = in_position;\n"
"}\n"
;
static const char skybox_shader_fs[] =
"#version 330 core\n"
"\n"
"in vec3 tex_coord;\n"
"\n"
"layout (location = 0) out vec4 color;\n"
"\n"
"uniform samplerCube tex;\n"
"\n"
"void main(void)\n"
"{\n"
" color = texture(tex, tex_coord);\n"
"}\n"
;
vglAttachShaderSource(skybox_prog, GL_VERTEX_SHADER, skybox_shader_vs);
vglAttachShaderSource(skybox_prog, GL_FRAGMENT_SHADER, skybox_shader_fs);
glLinkProgram(skybox_prog);
static const char object_shader_vs[] =
"#version 330 core\n"
"\n"
"layout (location = 0) in vec4 in_position;\n"
"layout (location = 1) in vec3 in_normal;\n"
"\n"
"out vec3 vs_fs_normal;\n"
"out vec3 vs_fs_position;\n"
"\n"
"uniform mat4 mat_mvp;\n"
"uniform mat4 mat_mv;\n"
"\n"
"void main(void)\n"
"{\n"
" gl_Position = mat_mvp * in_position;\n"
" vs_fs_normal = mat3(mat_mv) * in_normal;\n"
" vs_fs_position = (mat_mv * in_position).xyz;\n"
"}\n"
;
static const char object_shader_fs[] =
"#version 330 core\n"
"\n"
"in vec3 vs_fs_normal;\n"
"in vec3 vs_fs_position;\n"
"\n"
"layout (location = 0) out vec4 color;\n"
"\n"
"uniform samplerCube tex;\n"
"\n"
"void main(void)\n"
"{\n"
" vec3 tc = reflect(vs_fs_position, normalize(vs_fs_normal));\n"
" color = vec4(0.3, 0.2, 0.1, 1.0) + vec4(0.97, 0.83, 0.79, 0.0) * texture(tex, tc);\n"
"}\n"
;
object_prog = glCreateProgram();
vglAttachShaderSource(object_prog, GL_VERTEX_SHADER, object_shader_vs);
vglAttachShaderSource(object_prog, GL_FRAGMENT_SHADER, object_shader_fs);
glLinkProgram(object_prog);
glGenBuffers(1, &cube_vbo);
glBindBuffer(GL_ARRAY_BUFFER, cube_vbo);
static const GLfloat cube_vertices[] =
{
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f
};
//.........这里部分代码省略.........
开发者ID:ZYMing,项目名称:OpenGL-Shader,代码行数:101,代码来源:ch06_cube_map.cpp
示例17: Initialize
void InstanceIDExample::Initialize(const char * title)
{
int n;
base::Initialize(title);
// Create the program for rendering the model
render_prog = glCreateProgram();
// This is the rendering vertex shader
static const char render_vs[] =
"#version 410\n"
"\n"
"// 'position' and 'normal' are regular vertex attributes\n"
"layout (location = 0) in vec4 position;\n"
"layout (location = 1) in vec3 normal;\n"
"\n"
"// Color is a per-instance attribute\n"
"layout (location = 2) in vec4 color;\n"
"\n"
"// The view matrix and the projection matrix are constant across a draw\n"
"uniform mat4 view_matrix;\n"
"uniform mat4 projection_matrix;\n"
"\n"
"// These are the TBOs that hold per-instance colors and per-instance\n"
"// model matrices\n"
"uniform samplerBuffer color_tbo;\n"
"uniform samplerBuffer model_matrix_tbo;\n"
"\n"
"// The output of the vertex shader (matched to the fragment shader)\n"
"out VERTEX\n"
"{\n"
" vec3 normal;\n"
" vec4 color;\n"
"} vertex;\n"
"\n"
"// Ok, go!\n"
"void main(void)\n"
"{\n"
" // Use gl_InstanceID to obtain the instance color from the color TBO\n"
" vec4 color = texelFetch(color_tbo, gl_InstanceID);\n"
"\n"
" // Generating the model matrix is more complex because you can't\n"
" // store mat4 data in a TBO. Instead, we need to store each matrix\n"
" // as four vec4 variables and assemble the matrix in the shader.\n"
" // First, fetch the four columns of the matrix (remember, matrices are\n"
" // stored in memory in column-primary order).\n"
" vec4 col1 = texelFetch(model_matrix_tbo, gl_InstanceID * 4);\n"
" vec4 col2 = texelFetch(model_matrix_tbo, gl_InstanceID * 4 + 1);\n"
" vec4 col3 = texelFetch(model_matrix_tbo, gl_InstanceID * 4 + 2);\n"
" vec4 col4 = texelFetch(model_matrix_tbo, gl_InstanceID * 4 + 3);\n"
"\n"
" // Now assemble the four columns into a matrix.\n"
" mat4 model_matrix = mat4(col1, col2, col3, col4);\n"
"\n"
" // Construct a model-view matrix from the uniform view matrix\n"
" // and the per-instance model matrix.\n"
" mat4 model_view_matrix = view_matrix * model_matrix;\n"
"\n"
" // Transform position by the model-view matrix, then by the\n"
" // projection matrix.\n"
" gl_Position = projection_matrix * (model_view_matrix * position);\n"
" // Transform the normal by the upper-left-3x3-submatrix of the\n"
" // model-view matrix\n"
" vertex.normal = mat3(model_view_matrix) * normal;\n"
" // Pass the per-instance
|
请发表评论