void MarchingCubes::initUniforms( GLuint program ) { ////Samplers assignment/// glUniform1iARB(glGetUniformLocation(program, "dataFieldTex"), 1); glUniform1iARB(glGetUniformLocation(program, "edgeTableTex"), 2); glUniform1iARB(glGetUniformLocation(program, "triTableTex"), 3); ////Uniforms parameters//// //Initial isolevel glUniform1f(glGetUniformLocation(program, "isolevel"), treshold); //Step in data 3D texture for gradient computation (lighting) glUniform3f(glGetUniformLocation(program, "dataStep"), 1.0f/dataWidth, 1.0f/dataHeight, 1.0f/dataDepth); //Decal for each vertex in a marching cube float dx = 2.0f/dataWidth; float dy = 2.0f/dataHeight; float dz = 2.0f/dataDepth; glUniform3f(glGetUniformLocation(program, "vertDecals[0]"), 0.0f, 0.0f, 0.0f); glUniform3f(glGetUniformLocation(program, "vertDecals[1]"), dx, 0.0f, 0.0f); glUniform3f(glGetUniformLocation(program, "vertDecals[2]"), dx, dy, 0.0f); glUniform3f(glGetUniformLocation(program, "vertDecals[3]"), 0.0f, dy, 0.0f); glUniform3f(glGetUniformLocation(program, "vertDecals[4]"), 0.0f, 0.0f, dz); glUniform3f(glGetUniformLocation(program, "vertDecals[5]"), dx, 0.0f, dz); glUniform3f(glGetUniformLocation(program, "vertDecals[6]"), dx, dy, dz); glUniform3f(glGetUniformLocation(program, "vertDecals[7]"), 0.0f, dy, dz); }
void SingleChannelRaycaster::bindShader(const Raycaster::PTransform& pmv,const Raycaster::PTransform& mv,Raycaster::DataItem* dataItem) const { /* Call the base class method: */ Raycaster::bindShader(pmv,mv,dataItem); /* Get a pointer to the data item: */ DataItem* myDataItem=dynamic_cast<DataItem*>(dataItem); /* Bind the volume texture: */ glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_3D,myDataItem->volumeTextureID); glUniform1iARB(myDataItem->volumeSamplerLoc,1); /* Check if the volume texture needs to be updated: */ if(myDataItem->volumeTextureVersion!=dataVersion) { /* Upload the new volume data: */ glTexSubImage3DEXT(GL_TEXTURE_3D,0,0,0,0,dataSize[0],dataSize[1],dataSize[2],GL_LUMINANCE,GL_UNSIGNED_BYTE,data); /* Mark the volume texture as up-to-date: */ myDataItem->volumeTextureVersion=dataVersion; } /* Bind the color map texture: */ glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_1D,myDataItem->colorMapTextureID); glUniform1iARB(myDataItem->colorMapSamplerLoc,2); /* Create the stepsize-adjusted colormap with pre-multiplied alpha: */ GLColorMap adjustedColorMap(*colorMap); adjustedColorMap.changeTransparency(stepSize*transparencyGamma); adjustedColorMap.premultiplyAlpha(); glTexImage1D(GL_TEXTURE_1D,0,myDataItem->haveFloatTextures?GL_RGBA32F_ARB:GL_RGBA,256,0,GL_RGBA,GL_FLOAT,adjustedColorMap.getColors()); }
void Material::Render() { //load shader this->data.shader->Render(); GLuint shaderNumber = getShaderHandler(); //load textures to propper slots if(this->data.color != NULL) { GLint texture = glGetUniformLocationARB(shaderNumber, "texture0"); glActiveTextureARB(GL_TEXTURE0_ARB); this->data.color->Render(); glUniform1iARB(texture, 0); } if(this->data.color2 != NULL) { GLuint texture = glGetUniformLocationARB(shaderNumber, "texture1"); glActiveTextureARB(GL_TEXTURE1_ARB); this->data.color2->Render(); glUniform1iARB(texture, 1); } if(this->data.normal != NULL) { //GLuint texture = glGetUniformLocationARB(shaderNumber, "texture0"); this->data.normal->Render(); //glUniform1iARB(texture, 2); } }
void VoxGame::BeginShaderRender() { glShader* pShader = NULL; if (m_shadows) { m_pRenderer->BeginGLSLShader(m_shadowShader); pShader = m_pRenderer->GetShader(m_shadowShader); GLuint shadowMapUniform = glGetUniformLocationARB(pShader->GetProgramObject(), "ShadowMap"); m_pRenderer->PrepareShaderTexture(7, shadowMapUniform); m_pRenderer->BindRawTextureId(m_pRenderer->GetDepthTextureFromFrameBuffer(m_shadowFrameBuffer)); glUniform1iARB(glGetUniformLocationARB(pShader->GetProgramObject(), "renderShadow"), m_shadows); glUniform1iARB(glGetUniformLocationARB(pShader->GetProgramObject(), "alwaysShadow"), false); bool fogEnabled = true; glUniform1iARB(glGetUniformLocationARB(pShader->GetProgramObject(), "enableFog"), m_fogRender); float lfogEnd = m_pChunkManager->GetLoaderRadius() - Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE; float lfogStart = lfogEnd - Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE*2.0f; GLfloat fogColor[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 1.0f); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_START, lfogStart); glFogf(GL_FOG_END, lfogEnd); glEnable(GL_FOG); } else { m_pRenderer->BeginGLSLShader(m_defaultShader); } }
void VoxGame::RenderWater() { m_pRenderer->PushMatrix(); m_pRenderer->BeginGLSLShader(m_waterShader); glShader* pShader = pShader = m_pRenderer->GetShader(m_waterShader); unsigned int reflectionTexture = glGetUniformLocationARB(pShader->GetProgramObject(), "reflectionTexture"); unsigned int cubemapTexture = glGetUniformLocationARB(pShader->GetProgramObject(), "cubemap"); if (m_pChunkManager->IsUnderWater(m_pGameCamera->GetPosition()) == false) { glActiveTextureARB(GL_TEXTURE1_ARB); m_pRenderer->BindRawTextureId(m_pRenderer->GetDiffuseTextureFromFrameBuffer(m_waterReflectionFrameBuffer)); glUniform1iARB(reflectionTexture, 1); glActiveTextureARB(GL_TEXTURE0_ARB); m_pRenderer->BindCubeTexture(m_pSkybox->GetCubeMapTexture1()); glUniform1iARB(cubemapTexture, 0); } else { glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glActiveTextureARB(GL_TEXTURE0_ARB); m_pRenderer->DisableCubeTexture(); glActiveTextureARB(GL_TEXTURE1_ARB); } bool fogEnabled = true; glUniform1iARB(glGetUniformLocationARB(pShader->GetProgramObject(), "enableFog"), m_fogRender); float lfogEnd = m_pChunkManager->GetLoaderRadius() - Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE; float lfogStart = lfogEnd - Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE*2.0f; GLfloat fogColor[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 1.0f); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_START, lfogStart); glFogf(GL_FOG_END, lfogEnd); glEnable(GL_FOG); //pShader->setUniform1f("time", m_elapsedWaterTime); m_pRenderer->TranslateWorldMatrix(m_pPlayer->GetCenter().x, 0.0f, m_pPlayer->GetCenter().z); m_pChunkManager->RenderWater(); glDisable(GL_FOG); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glActiveTextureARB(GL_TEXTURE0_ARB); m_pRenderer->DisableCubeTexture(); m_pRenderer->EndGLSLShader(m_waterShader); m_pRenderer->PopMatrix(); }
void cDeferredRenderer::Begin() { //LightPass.Begin() glEnable(GL_BLEND); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0,mWidth,0,mHeight,0.1f,2); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glUseProgramObjectARB(mShader->GetID()); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, mFBORenderTexture->GetDiffuseTexture()); glUniform1iARB ( mDiffuseID, 0 ); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, mFBORenderTexture->GetPositionTexture()); glUniform1iARB ( mPositionID, 1 ); glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_2D, mFBORenderTexture->GetNormalsTexture()); glUniform1iARB ( mNormalsID, 2 ); glLoadIdentity(); glTranslatef(0,0,-1); }
/** * Render the big quad with the deferred rendering shader on it */ void DeferredRendering::render() { glUseProgram(m_shader.m_shaderProg); glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_fboRenderTexture.getDiffuseTexture()); glUniform1iARB ( m_diffuseLoc, 0 ); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_fboRenderTexture.getPositionTexture()); glUniform1iARB ( m_positionLoc, 1 ); glActiveTextureARB(GL_TEXTURE2_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_fboRenderTexture.getNormalsTexture()); glUniform1iARB ( m_normalsLoc, 2 ); glActiveTextureARB(GL_TEXTURE3_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_shadowMap.getTexture()); glUniform1iARB ( m_shadowMapLoc, 3 ); glUniformMatrix4fv ( m_worldToCameraViewMatrixLoc, 1, GL_FALSE, (const GLfloat*)m_worldToCameraViewMatrix.m_matrix ); glUniformMatrix4fv ( m_lightViewToProjectionMatrixLoc, 1, GL_FALSE, (const GLfloat*)m_lightViewToProjectionMatrix.m_matrix ); glUniformMatrix4fv ( m_worldToLightViewMatrixLoc, 1, GL_FALSE, (const GLfloat*)m_worldToLightViewMatrix.m_matrix ); // Render the quad m_screenQuad->render(false); // Reset OpenGL state glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glActiveTextureARB(GL_TEXTURE3_ARB); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(0); }
void LightPass::UpdateShader(Camera& camera) { glUseProgram(LightPass::m_pointLightShader->GetProgram()); int screenWidth, screenHeight; glfwGetWindowSize(Display::GetCurrentDisplay()->GetWindow(), &screenWidth, &screenHeight); glUniform2f(m_screenSize_u, screenWidth, screenHeight); glUniform3fv(m_eyePosition, 1, glm::value_ptr((glm::vec3)camera.GetTransform().position)); glUniform1f(m_hdrExposure_u, m_hdrExposure); glUniform1iARB(m_colorTexture_u, 0); glUniform1iARB(m_positionsTexture_u, 1); glUniform1iARB(m_normalsTexture_u, 2); glUniform1iARB(m_lightTexture_u, 3); }
// The shader must be activated before void Shader::UniformTexture(const std::string& ext, GLint slot) { glActiveTexture(GL_TEXTURE0+slot); // if(pTex) pTex->Bind(slot); int id = glGetUniformLocation(m_nProgram, ext.c_str()); glUniform1iARB(id, slot); }
void pip::Shader::setSampler(const string &uniformName, Texture *texture) { if(this->samplersToUnitMap.count(uniformName) == 0) { this->samplersToUnitMap[uniformName] = currentTextureUnit; currentTextureUnit++; } if(this->samplersToLocationsMap.count(uniformName) == 0) { GLint tex_sampler = glGetUniformLocationARB(this->prog, uniformName.c_str()); std::cout << "location: " <<tex_sampler << std::endl; string err; getOGLErrors(err); if(!err.empty()) throw EngineException("Errors while getting texture sampler:\n" + err); this->samplersToLocationsMap[uniformName] = tex_sampler; } glActiveTexture(GL_TEXTURE0 + this->samplersToUnitMap[uniformName]); // Activate texture unit. texture->bind(); glUniform1iARB(this->samplersToLocationsMap[uniformName], this->samplersToUnitMap[uniformName]); // TODO But what, if referring to inexistent texture unit? glActiveTexture(GL_TEXTURE0); string err; getOGLErrors(err); if(!err.empty()) throw EngineException("Errors while setting texture sampler:\n" + err); }
/* * sendUniform1i * * parameter name - char* * parameter value - GLint * return - bool */ bool ShaderObject::sendUniform1i(const char * name, GLint value) { GLint location = getUniLoc(name); if (location == -1) return false; glUniform1iARB(location, value); return true; } // end sendUniform1i()
bool draw(U32 pass) { if((S32)pass > mNumPasses*2) return false; glUniform1iARB(mPassLoc, (pass-1) % 2); return true; }
struct glmaxsrc_ctx *maxsrc_new_glsl(int width, int height, GLboolean packed_intesity_pixels) { printf("Compiling maxsrc shader:\n"); const char *defs = packed_intesity_pixels?"#version 110\n#define FLOAT_PACK_PIX\n":"#version 110\n"; GLuint prog = compile_program_defs(defs, vtx_shader, frag_src); GLint R_loc = -1; if(!prog) return NULL; printf("maxsrc shader compiled\n"); glUseProgramObjectARB(prog); glUniform1iARB(glGetUniformLocationARB(prog, "prev"), 0); R_loc = glGetUniformLocationARB(prog, "R"); glUseProgramObjectARB(0); CHECK_GL_ERR; int samp = MIN(MIN(width/8, height/8), 128); printf("maxsrc using %i points\n", samp); struct priv_ctx *priv = calloc(sizeof(*priv), 1); priv->pubctx.update = update; priv->pubctx.offscr = offscr_new(width, height, false, !packed_intesity_pixels); priv->glscope = gl_scope_init(width, height, samp, false); priv->prog = prog; priv->R_loc = R_loc; return &priv->pubctx; }
void GLSL_ShaderPair::applyTexture ( const char *uniformName, FrameBufferObject *fbo, int slot ) { fbo -> use ( slot ) ; glUniform1iARB ( getUniformLocation ( uniformName ), slot ) ; }
void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUTexture *tex) { GLenum arbnumber; if (tex->number >= GG.maxtextures) { GPU_print_error("Not enough texture slots."); return; } if (tex->number == -1) return; if (location == -1) return; GPU_print_error("Pre Uniform Texture"); arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number); if (tex->number != 0) glActiveTextureARB(arbnumber); glBindTexture(tex->target, tex->bindcode); glUniform1iARB(location, tex->number); glEnable(tex->target); if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB); GPU_print_error("Post Uniform Texture"); }
void ShaderCustomTex::setTextureUnit(GLenum texture_unit) { this->bind(); int unit = texture_unit - GL_TEXTURE0; glUniform1iARB(*m_unif_unit,unit); m_unit = unit; }
void glut_viewer_draw_skybox(int cube_texture) { glDepthMask(GL_FALSE) ; glDisable(GL_LIGHTING) ; glEnable(GL_TEXTURE_CUBE_MAP_ARB) ; glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cube_texture); glColor3f(1,1,1) ; glCullFace(GL_FRONT) ; glEnable(GL_CULL_FACE) ; glUseProgramObjectARB(skybox_shader); glUniform1iARB(cube_texture, 0); glutSolidCube(3) ; glUseProgramObjectARB(0); glDisable(GL_TEXTURE_CUBE_MAP_ARB) ; glDisable(GL_CULL_FACE) ; glDepthMask(GL_TRUE) ; }
void WShaderProgram::setValue1i( const char *name, int v1 ) { GLint loc = glGetUniformLocationARB( programId(), name ); glUniform1iARB( loc, v1 ); GLenum err = glGetError(); const GLubyte *msg = gluErrorString( err ); }
void ShaderTextureBlurH::setTextureUnit(GLenum textureUnit) { this->bind(); int unit = textureUnit - GL_TEXTURE0; glUniform1iARB(*m_unifTexUnit, unit); m_texUnit = unit; }
static void render_textbox(char * text, int width, int height) { GLint location; glUseProgramObjectARB(text_shader); location = glGetUniformLocationARB(text_shader, "iResolution"); glUniform2fARB(location, width, height); int text_w; int text_h; SDL_Texture * tex = render_text(text, &text_w, &text_h); location = glGetUniformLocationARB(text_shader, "iTextResolution"); glUniform2fARB(location, text_w, text_h); location = glGetUniformLocationARB(text_shader, "iText"); glUniform1iARB(location, 0); glActiveTexture(GL_TEXTURE0); SDL_GL_BindTexture(tex, NULL, NULL); glLoadIdentity(); gluOrtho2D(0, width, 0, height); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT); fill(width, height); SDL_DestroyTexture(tex); }
void CShadersManager::SetSampler2D (const char * name, GLint value) { if(this->IsShadersAvailable()) { GLint loc = glGetUniformLocationARB(this->Programs[this->Program].GetHandle(), name); glUniform1iARB(loc, value); } }
struct glpal_ctx * pal_init_glsl(GLboolean float_packed_pixels) {CHECK_GL_ERR; printf("Compiling pallet shader:\n"); GLint prog = 0; if(!float_packed_pixels) prog = compile_program(vtx_shader, pal_frag_shader); else prog = compile_program(vtx_shader, pal_frag_mix); if(!prog) return NULL; struct pal_lst *pals = pallet_get_palettes(); struct priv_ctx *priv = malloc(sizeof(*priv) + sizeof(*priv->pal_tex)*pals->numpals); priv->pubctx.render = render; priv->pubctx.step = step; priv->pubctx.start_switch = start_switch; priv->pubctx.changing = changing; priv->prog = prog; priv->numpal = pals->numpals; priv->curpal = priv->nextpal = 0; priv->palpos = 0; glUseProgramObjectARB(prog); glUniform1iARB(glGetUniformLocationARB(prog, "src"), 0); glUniform1iARB(glGetUniformLocationARB(prog, "pal1"), 1); glUniform1iARB(glGetUniformLocationARB(prog, "pal2"), 2); priv->palpos_loc = glGetUniformLocationARB(prog, "palpos"); glUniform1fARB(priv->palpos_loc, 0.0f); glUseProgramObjectARB(0); printf("Pallet shader compiled\n"); glGenTextures(pals->numpals, priv->pal_tex); glPushAttrib(GL_TEXTURE_BIT); for(int i=0; i<pals->numpals; i++) { glBindTexture(GL_TEXTURE_1D, priv->pal_tex[i]); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, pals->pallets[i]); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } glPopAttrib(); CHECK_GL_ERR; free(pals); return (struct glpal_ctx *)priv; }
struct glpal_ctx *pal_init_glsl(GLboolean float_packed_pixels) {CHECK_GL_ERR; printf("Compiling pallet shader:\n"); GLint prog = 0; if(!float_packed_pixels) prog = compile_program(vtx_shader, pal_frag_shader); else prog = compile_program(vtx_shader, pal_frag_mix); if(!prog) return NULL; glUseProgramObjectARB(prog); glUniform1iARB(glGetUniformLocationARB(prog, "src"), 0); glUniform1iARB(glGetUniformLocationARB(prog, "pal"), 1); glBindAttribLocationARB(prog, 0, "vertex"); glUseProgramObjectARB(0); printf("Pallet shader compiled\n"); struct priv_ctx *priv = malloc(sizeof(*priv)); priv->pubctx.render = render; priv->pubctx.step = pal_step; priv->pubctx.start_switch = start_switch; priv->pubctx.changing = changing; priv->pal = pal_ctx_new(0); priv->prog = prog; priv->cnt = 0; glGenTextures(2, &priv->tex); glBindTexture(GL_TEXTURE_1D, priv->tex[0]); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, pal_ctx_get_active(priv->pal)); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_1D, 0); glBindTexture(GL_TEXTURE_1D, priv->tex[1]); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, pal_ctx_get_active(priv->pal)); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_1D, 0); CHECK_GL_ERR; return (struct glpal_ctx *)priv; }
void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value) { if (location == -1) return; GPU_print_error("Pre Uniform Int"); glUniform1iARB(location, value); GPU_print_error("Post Uniform Int"); }
static void bind_texture_arb (cairo_gl_shader_t *shader, const char *name, cairo_gl_tex_t tex_unit) { GLint location = glGetUniformLocationARB (shader->program, name); assert (location != -1); glUniform1iARB (location, tex_unit); }
bool GlslProgram :: setTexture ( int loc, int texUnit ) { if ( loc < 0 ) return false; glUniform1iARB ( loc, texUnit ); return true; }
bool Shader::sendUniform1i(char* varname, GLint v0) { GLint loc = GetUniformLocation(varname); if (loc == -1) return false; glUniform1iARB(loc, v0); return true; }
void Shader::SetInt(std::string name, int value) { int uloc = SIG_FindUniform(name); if (uloc != -1) { glUniform1iARB(uloc, value); } else { SIG_LOG("Could not find uniform \"" << name << "\""); } }
int bind_shadow2shader(camera3d_t light,GLuint* shadowFBO,GLuint shader) { glPopAttrib(); glCullFace(GL_BACK); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgramObjectARB(shader); glActiveTextureARB(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, shadowFBO[1]); glUniform1iARB(glGetUniformLocationARB(shader,"shadowmap"), 1); glUniform1iARB(glGetUniformLocationARB(shader,"tex"), 0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glLoadMatrixd(light+BIAS); glMultMatrixd(light+PROJECTION); glMultMatrixd(light+VIEW); glActiveTextureARB(GL_TEXTURE0); return 0; }
void RenderScene() { // Model matrix : being updated by idle // Our ModelViewProjection : multiplication of our 3 matrices MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around // Use our shader glUseProgram(ShaderMainProgramId); // Send our transformation to the currently bound shader, in the "MVP" uniform glUniformMatrix4fv(MainShaderMvpId, 1, GL_FALSE, &MVP[0][0]); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Bind texture to texture unit glActiveTexture(GL_TEXTURE0); // change active texture unit to number 0 glBindTexture(GL_TEXTURE_2D, TextureId); // bind the texture to the active texture unit (which is now 0) // Bind shader variable "Texture" to texture unit glUniform1iARB(MainShaderTextureId, 0); // Notice the 0 to indicate you want to sample from the texture bound to Texture Unit GL_TEXTURE0. float imageRatio = (float)theTexMap.GetNumCols() / theTexMap.GetNumRows(); if (imageRatio > 1) { imageRatio = 1.0 / imageRatio; } glBegin(GL_QUADS); glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 0.0, -1.0*imageRatio); glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 0.0, 1.0*imageRatio); glTexCoord2f(1.0, 0.0); glVertex3f(1.0, 0.0, 1.0*imageRatio); glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 0.0, -1.0*imageRatio); glEnd(); // Draw groups glUseProgram(ShaderModelProgramId); glUniformMatrix4fv(ModelShaderMvpId, 1, GL_FALSE, &MVP[0][0]); int modelNum = 0; for (std::vector<Group>::iterator it = (*Data).begin(); it != (*Data).end(); ++it) { RenderGroup(it->items, it->color, modelNum++); RenderGroupCount(it->items.size(), 0); } glutWarpPointer(g_iWindowWidth/2, g_iWindowHeight/2); }