本文整理汇总了C++中GLShader::p方法的典型用法代码示例。如果您正苦于以下问题:C++ GLShader::p方法的具体用法?C++ GLShader::p怎么用?C++ GLShader::p使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLShader
的用法示例。
在下文中一共展示了GLShader::p方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doit
/**
* Prepare to run the intro
**/
void Intro::doit()
{
GLShader *shader;
if (sg->music != NULL) {
GEng()->audio->playSong(sg);
}
start = SDL_GetTicks();
lasttime = 0;
CHECK_OPENGL_ERROR
// Find 'basic' shader
map<int, GLShader*>::const_iterator pos = render->shaders.find(SHADER_BASIC);
if (pos == render->shaders.end()) {
assert(false);
} else {
shader = pos->second;
}
// Set shader and uniforms
glUseProgram(shader->p());
glm::mat4 projection = glm::ortho<float>(
0.0f, static_cast<float>(this->render->getWidth()),
static_cast<float>(this->render->getHeight()), 0.0f,
1.0f, -1.0f
);
glUniformMatrix4fv(shader->uniform("uMVP"), 1, GL_FALSE, &projection[0][0]);
glUniform1i(shader->uniform("uTex"), 0);
CHECK_OPENGL_ERROR
this->updateUI();
}
示例2: drawString
/**
* Draws a string.
*
* NOTE: You normally won't use this function to draw text since
* Graphics contains better functions for drawing text.
*
* @param graphics A Graphics object to use for drawing.
* @param text The string to draw.
* @param x The x coordinate where to draw the string.
* @param y The y coordinate where to draw the string.
*/
void OpenGLFont::drawString(gcn::Graphics* graphics, const std::string& text, int x, int y, float r, float g, float b, float a)
{
float xx, yy;
if (this->pmpl->font_vbo == 0) {
glGenVertexArrays(1, &this->pmpl->font_vao);
glGenBuffers(1, &this->pmpl->font_vbo);
}
glBindVertexArray(this->pmpl->font_vao);
glEnable(GL_BLEND);
// Set up shader
GLShader* shader = this->render->shaders[SHADER_TEXT];
glUseProgram(shader->p());
glUniform1i(shader->uniform("uTex"), 0);
glUniform4f(shader->uniform("uColor"), r, g, b, a);
if (graphics == NULL) {
// If in standard mode, use the values as-is
xx = (float)x;
yy = (float)y;
glUniformMatrix4fv(shader->uniform("uMVP"), 1, GL_FALSE, glm::value_ptr(this->render->ortho));
} else {
// If in Guichan mode, use the current clip area
const gcn::ClipRectangle& top = graphics->getCurrentClipArea();
xx = (float)(x + top.xOffset);
yy = (float)(y + top.yOffset) + this->size;
glUniformMatrix4fv(shader->uniform("uMVP"), 1, GL_FALSE, glm::value_ptr(this->render->ortho_guichan));
}
// Render each character
const char* ptr = text.c_str();
size_t textlen = strlen(ptr);
while (textlen > 0) {
Uint32 c = UTF8_getch(&ptr, &textlen);
if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) {
continue;
}
this->renderCharacter(c, xx, yy);
}
glDisable(GL_BLEND);
CHECK_OPENGL_ERROR;
}
示例3: createShader
/**
* Create a shader, optimised for the specific splat rendering used
**/
GLShader* RendererHeightmap::createShader(RenderOpenGL* render, Heightmap* heightmap)
{
CHECK_OPENGL_ERROR;
GLShader* s = new GLShader(0);
char* vertex_code = s->loadCodeFile("phong_static.glslv");
GLuint vertex = s->createShader(GL_VERTEX_SHADER, vertex_code);
free(vertex_code);
if (vertex == 0) {
GL_LOG("Invalid vertex shader");
return NULL;
}
char* base_fragment_code = s->loadCodeFile("phong_splat.glslf");
char* diffuse_code = RendererHeightmap::createShaderFunction_diffuseColor(heightmap);
const char* strings[3];
strings[0] = "#version 130\n";
strings[1] = base_fragment_code;
strings[2] = diffuse_code;
GLuint fragment = s->createShader(GL_FRAGMENT_SHADER, 3, strings);
free(base_fragment_code);
free(diffuse_code);
if (fragment == 0) {
glDeleteShader(vertex);
GL_LOG("Invalid fragment shader");
return NULL;
}
bool result = s->createProgFromShaders(vertex, fragment);
glDeleteShader(vertex);
glDeleteShader(fragment);
if (!result) {
return NULL;
}
glUseProgram(s->p());
glUniform1i(s->uniform("uTex"), 0);
glUniform1i(s->uniform("uShadowMap"), 1);
glUniform1i(s->uniform("uNormal"), 2);
glUniform1i(s->uniform("uLightmap"), 3);
glUniform1i(s->uniform("uDayNight"), 4);
glUniform1i(s->uniform("uAlphaMap"), 0);
glUniform1i(s->uniform("uLayers[0]"), 5);
glUniform1i(s->uniform("uLayers[1]"), 6);
glUniform1i(s->uniform("uLayers[2]"), 7);
glUniform1i(s->uniform("uLayers[3]"), 8);
glUniform1i(s->uniform("uLightmap"), 9);
glUniform1i(s->uniform("uDetail[0]"), 10);
glUniform1i(s->uniform("uDetail[1]"), 11);
glUniform1i(s->uniform("uDetail[2]"), 12);
glUniform1i(s->uniform("uDetail[3]"), 13);
CHECK_OPENGL_ERROR;
return s;
}