本文整理汇总了C++中ShaderProgram::create方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::create方法的具体用法?C++ ShaderProgram::create怎么用?C++ ShaderProgram::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw_integer
void MeshRenderer::draw_integer(unsigned int name)
{
if (!data_ || !data_->vertices || !data_->triangles)
return;
//set up vertex array object
if (update_)
{
update();
update_ = false;
}
ShaderProgram* shader = 0;
glBindVertexArray(m_vao);
GLMgroup* group = data_->groups;
GLint pos = 0;
//set up shader
shader = msh_shader_factory_.shader(1,
0, false, false, false);
if (shader)
{
if (!shader->valid())
shader->create();
shader->bind();
}
//uniforms
shader->setLocalParamMatrix(0, glm::value_ptr(m_proj_mat));
shader->setLocalParamMatrix(1, glm::value_ptr(m_mv_mat));
shader->setLocalParamUInt(0, name);
while (group)
{
if (group->numtriangles == 0)
{
group = group->next;
continue;
}
//draw
glDrawArrays(GL_TRIANGLES, pos, (GLsizei)(group->numtriangles*3));
pos += group->numtriangles*3;
group = group->next;
}
glBindVertexArray(0);
// Release shader.
if (shader && shader->valid())
shader->release();
}
示例2: main
int main(int argc, char *argv[])
{
device = CreateDevice(Vector2i(800, 600), "R3D Engine 2.0");
char buf[128];
int fps=0;
double lastTime=device->getTime();
TextureManager *tm = device->getTextureManager();
RenderTarget *rt = BuildGBuffer(device, {800, 600});
ShaderProgram *program = device->addShaderProgram();
program->create(LoadFile("vs2.txt").c_str(), LoadFile("fs2.txt").c_str());
GLuint id;
glGenVertexArrays(1, &id);
auto *camera = device->getSceneManager()->getCamera();
while(device->isRunning()) {
device->update();
if(device->getInput()->isKeyDown(KeyCode::KEY_ESCAPE))
device->stop();
if(device->getInput()->isKeyDown(KeyCode::KEY_L))
tm->loadTextureFromFileAsync("./water.png", "water.png", nullptr);
if(device->getInput()->isKeyDown(KeyCode::KEY_M))
device->getSceneManager()->loadWavefrontAsync("sponza/sponza.obj");
//auto view = LookAt({100.f, 100.f, 100.f}, {0.f}, {0.f, 1.f, 0.f});
program->setUniform("vp", camera->getProjectionMatrix()*camera->getViewMatrix());
program->setUniform("v", Matrix4(Matrix3(camera->getViewMatrix())));
device->getDefaultRenderTarget()->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
program->use();
device->getSceneManager()->drawAll();
/*
glBindVertexArray(id);
program->use();
tm->fetchTexture("./water.png")->bind(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
*/
device->swapBuffers();
fps++;
if(device->getTime() - lastTime>1.0) {
sprintf(buf, "R3D Engine 2.0 - %.1f fps", device->getFrameRate());
device->setWindowCaption(buf);
fps=0;
lastTime = device->getTime();
}
}
DestroyDevice(device);
return 0;
}
示例3: draw_wireframe
void MeshRenderer::draw_wireframe()
{
if (!data_ || !data_->vertices || !data_->triangles)
return;
//set up vertex array object
if (update_)
{
update();
update_ = false;
}
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
ShaderProgram* shader = 0;
glBindVertexArray(m_vao);
GLMgroup* group = data_->groups;
GLint pos = 0;
int peel = 0;
bool tex = false;
bool light = false;
//set up shader
shader = msh_shader_factory_.shader(0,
peel, tex, fog_, light);
if (shader)
{
if (!shader->valid())
shader->create();
shader->bind();
}
//uniforms
shader->setLocalParamMatrix(0, glm::value_ptr(m_proj_mat));
shader->setLocalParamMatrix(1, glm::value_ptr(m_mv_mat));
GLMmaterial* material = &data_->materials[0];
if (material)
shader->setLocalParam(0, material->diffuse[0], material->diffuse[1], material->diffuse[2], material->diffuse[3]);
else
shader->setLocalParam(0, 1.0, 0.0, 0.0, 1.0);
shader->setLocalParam(3, 0.0, 1.0, 0.0, 0.0);//alpha
if (fog_)
shader->setLocalParam(8, m_fog_intensity, m_fog_start, m_fog_end, 0.0);
while (group)
{
if (group->numtriangles == 0)
{
group = group->next;
continue;
}
//draw
glDrawArrays(GL_TRIANGLES, pos, (GLsizei)(group->numtriangles*3));
pos += group->numtriangles*3;
group = group->next;
}
glBindVertexArray(0);
// Release shader.
if (shader && shader->valid())
shader->release();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
示例4: draw
void MeshRenderer::draw()
{
if (!data_ || !data_->vertices || !data_->triangles)
return;
//set up vertex array object
if (update_)
{
update();
update_ = false;
}
GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
ShaderProgram* shader = 0;
glBindVertexArray(m_vao);
GLMgroup* group = data_->groups;
GLint pos = 0;
bool tex = data_->hastexture==GL_TRUE;
while (group)
{
if (group->numtriangles == 0)
{
group = group->next;
continue;
}
//set up shader
shader = msh_shader_factory_.shader(0,
depth_peel_, tex, fog_, light_);
if (shader)
{
if (!shader->valid())
shader->create();
shader->bind();
}
//uniforms
shader->setLocalParamMatrix(0, glm::value_ptr(m_proj_mat));
shader->setLocalParamMatrix(1, glm::value_ptr(m_mv_mat));
if (light_)
{
glm::mat4 normal_mat = glm::mat4(glm::inverseTranspose(glm::mat3(m_mv_mat)));
shader->setLocalParamMatrix(2, glm::value_ptr(normal_mat));
GLMmaterial* material = &data_->materials[group->material];
if (material)
{
shader->setLocalParam(0, material->ambient[0], material->ambient[1], material->ambient[2], material->ambient[3]);
shader->setLocalParam(1, material->diffuse[0], material->diffuse[1], material->diffuse[2], material->diffuse[3]);
shader->setLocalParam(2, material->specular[0], material->specular[1], material->specular[2], material->specular[3]);
shader->setLocalParam(3, material->shininess, alpha_, 0.0, 0.0);
}
}
else
{//color
GLMmaterial* material = &data_->materials[group->material];
if (material)
shader->setLocalParam(0, material->diffuse[0], material->diffuse[1], material->diffuse[2], material->diffuse[3]);
else
shader->setLocalParam(0, 1.0, 0.0, 0.0, 1.0);//color
shader->setLocalParam(3, 0.0, alpha_, 0.0, 0.0);//alpha
}
if (tex)
{
GLMmaterial* material = &data_->materials[group->material];
if (material)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,
material->textureID);
}
}
if (fog_)
shader->setLocalParam(8, m_fog_intensity, m_fog_start, m_fog_end, 0.0);
if (depth_peel_)
shader->setLocalParam(7, 1.0/double(vp[2]), 1.0/double(vp[3]), 0.0, 0.0);
//draw
glDrawArrays(GL_TRIANGLES, pos, (GLsizei)(group->numtriangles*3));
pos += group->numtriangles*3;
group = group->next;
}
glBindVertexArray(0);
// Release shader.
if (shader && shader->valid())
shader->release();
//release texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
}