void TextureFactory::set_parameters(const TexturePtr &texture, const TextureFormat &format) { for (const ITextureParameterPtr ¶m : format.get_parameters()) { if (ITextureParameter::is_type<int>(param)) { auto int_param = std::static_pointer_cast<TextureParameter<int>>(param); glTexParameteri(format.get_type(), param->get_name(), int_param->get_param()); } else if (ITextureParameter::is_type<float>(param)) { auto float_param = std::static_pointer_cast<TextureParameter<float>>(param); glTexParameterf(format.get_type(), param->get_name(), float_param->get_param()); } else if (ITextureParameter::is_type<glm::ivec4>(param)) { auto int_params = std::static_pointer_cast<TextureParameter<glm::ivec4>>(param); glTexParameteriv(format.get_type(), param->get_name(), glm::value_ptr(int_params->get_param())); } else if (ITextureParameter::is_type<glm::vec4>(param)) { auto float_params = std::static_pointer_cast<TextureParameter<glm::vec4>>(param); glTexParameterfv(format.get_type(), param->get_name(), glm::value_ptr(float_params->get_param())); } } }
void ImageKnob::onDisplay() { const float normValue = (fValue - fMinimum) / (fMaximum - fMinimum); if (fRotationAngle != 0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, fTextureId); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWidth(), getHeight(), 0, fImage.getFormat(), fImage.getType(), fImage.getRawData()); 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_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); float trans[] = { 0.0f, 0.0f, 0.0f, 0.0f }; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, trans); glPushMatrix(); const GLint w2 = getWidth()/2; const GLint h2 = getHeight()/2; glTranslatef(getX()+w2, getY()+h2, 0.f); glRotatef(normValue*fRotationAngle, 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2i(-w2, -h2); glTexCoord2f(1.0f, 1.0f); glVertex2i(getWidth()-w2, -h2); glTexCoord2f(1.0f, 0.0f); glVertex2i(getWidth()-w2, getHeight()-h2); glTexCoord2f(0.0f, 0.0f); glVertex2i(-w2, getHeight()-h2); glEnd(); glPopMatrix(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } else { const int layerDataSize = fImgLayerSize * fImgLayerSize * ((fImage.getFormat() == GL_BGRA || fImage.getFormat() == GL_RGBA) ? 4 : 3); const int imageDataSize = layerDataSize * fImgLayerCount; const int imageDataOffset = imageDataSize - layerDataSize - (layerDataSize * int(normValue * float(fImgLayerCount-1))); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); glRasterPos2i(getX(), getY()+getHeight()); glDrawPixels(fImgLayerSize, fImgLayerSize, fImage.getFormat(), fImage.getType(), fImage.getRawData() + imageDataOffset); } }
QOpenGLFramebufferObject* TextureCache::getShadowFramebufferObject() { if (!_shadowFramebufferObject) { const int SHADOW_MAP_SIZE = 2048; _shadowFramebufferObject = new QOpenGLFramebufferObject(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGB); glGenTextures(1, &_shadowDepthTextureID); glBindTexture(GL_TEXTURE_2D, _shadowDepthTextureID); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); const float DISTANT_BORDER[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, DISTANT_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glBindTexture(GL_TEXTURE_2D, 0); _shadowFramebufferObject->bind(); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _shadowDepthTextureID, 0); _shadowFramebufferObject->release(); } return _shadowFramebufferObject; }
void FBOTexture::CreateShadowmap(int resolution, int quality) { if (quality == GFX_SHADOWS_DISABLED) return; GLenum err; //Initialize Shadowmap texture, parameters should be configurable through settings glGenTextures(1, &m_textureHandle); glBindTexture(GL_TEXTURE_2D, m_textureHandle); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); // Create 2 channel texture for variance shadowmapping glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, resolution, resolution, 0, GL_RG, GL_FLOAT, nullptr); GLfloat border[4] = { 1.0f, 1.0f, 0.0f, 0.0f }; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); glGenerateMipmap(GL_TEXTURE_2D); m_width = resolution; m_height = resolution; }
void GL::Texture::setSamplingState(TextureTarget target, const SamplingState& state) { if (state.isParameterSet(SamplingState::Parameter::WrapS)) glTexParameteri(GLenum(target), GL_TEXTURE_WRAP_S, GLint(state.wrap.s)); if (state.isParameterSet(SamplingState::Parameter::WrapT)) glTexParameteri(GLenum(target), GL_TEXTURE_WRAP_T, GLint(state.wrap.t)); if (state.isParameterSet(SamplingState::Parameter::WrapR)) glTexParameteri(GLenum(target), GL_TEXTURE_WRAP_R, GLint(state.wrap.r)); if (state.isParameterSet(SamplingState::Parameter::MinFilter)) glTexParameteri(GLenum(target), GL_TEXTURE_MIN_FILTER, GLint(state.filter.min)); if (state.isParameterSet(SamplingState::Parameter::MagFilter)) glTexParameteri(GLenum(target), GL_TEXTURE_MAG_FILTER, GLint(state.filter.mag)); if (state.isParameterSet(SamplingState::Parameter::BorderColor)) glTexParameterfv(GLenum(target), GL_TEXTURE_BORDER_COLOR, &(state.borderColor.r)); if (state.isParameterSet(SamplingState::Parameter::MinLOD)) glTexParameterf(GLenum(target), GL_TEXTURE_MIN_LOD, state.LOD.min); if (state.isParameterSet(SamplingState::Parameter::MaxLOD)) glTexParameterf(GLenum(target), GL_TEXTURE_MAX_LOD, state.LOD.max); if (state.isParameterSet(SamplingState::Parameter::LODbias)) glTexParameterf(GLenum(target), GL_TEXTURE_LOD_BIAS, state.LOD.bias); if (state.isParameterSet(SamplingState::Parameter::CompareMode)) glTexParameteri(GLenum(target), GL_TEXTURE_COMPARE_MODE, GLint(state.compare.mode)); if (state.isParameterSet(SamplingState::Parameter::CompareFunc)) glTexParameteri(GLenum(target), GL_TEXTURE_COMPARE_FUNC, GLint(state.compare.func)); }
void Texture::CreateDepthBuffer(int width, int height) { this->width = width; this->height = height; samplerName = "depth_map"; glGenFramebuffers(1, &frameBufferID); glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 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_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); GLfloat borderColor[] = { 1.0f, 0.0f, 0.0f, 0.0f }; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS); glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureID, 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glBindFramebuffer(GL_FRAMEBUFFER, 0); }
void TextureMain::loadLightMapTexture(Model_IMG* model, string file) { GLfloat eyePlaneS[] = {1.0f, 0.0f, 0.0f, 0.0f}; GLfloat eyePlaneT[] = {0.0f, 1.0f, 0.0f, 0.0f}; GLfloat eyePlaneR[] = {0.0f, 0.0f, 1.0f, 0.0f}; GLfloat eyePlaneQ[] = {0.0f, 0.0f, 0.0f, 1.0f}; GLfloat borderColor[] = {1.f, 1.f, 1.f, 1.0f}; glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glTexGenfv(GL_S,GL_EYE_PLANE,eyePlaneS); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glTexGenfv(GL_T,GL_EYE_PLANE,eyePlaneT); glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glTexGenfv(GL_R,GL_EYE_PLANE,eyePlaneR); glTexGeni(GL_Q,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR); glTexGenfv(GL_Q,GL_EYE_PLANE,eyePlaneQ); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_GEN_Q); model->Load(file); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 0x812D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 0x812D); glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,borderColor); gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,model->Width,model->Height,GL_RGB,GL_UNSIGNED_BYTE,model->Pixels); }
static void InitSpecial(void) { GLubyte textureData[32 * 32]; float testAni = 16; int x, y; GLint err; for (x = 0; x < 32; x++) { for (y = 0; y < 32; y++) { if ((x < 16 && y < 16) || (x >= 16 && y >= 16)) textureData[y * 32 + x] = 0; else textureData[y * 32 + x] = 255; } } /* Create the tile texture. */ glGenTextures(4, texture); #ifdef MULTIPLE_VIEWPORTS /* Create Bilinear Filtered Texture */ glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 32, 32, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, textureData); /* Create Bilinear MipMapped Texture */ glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); err =gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, 32, 32, GL_LUMINANCE, GL_UNSIGNED_BYTE, textureData); /* Create Trilinear MipMapped Texture */ glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); err = gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, 32, 32, GL_LUMINANCE, GL_UNSIGNED_BYTE, textureData); #endif /* Create Anisotropic Texture */ glBindTexture(GL_TEXTURE_2D, texture[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterfv(GL_TEXTURE_2D, (GLenum) GL_TEXTURE_MAX_ANISOTROPY_EXT, &testAni); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 32, 32, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, textureData); glGetTexParameterfv(GL_TEXTURE_2D, (GLenum) GL_TEXTURE_MAX_ANISOTROPY_EXT, &testAni); printf("Current Anisotropy: %f", testAni); }
void ReInit(void) { if (genericObject == torus) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } if (isFogged) { textureEnvironment = modulate; } glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textureEnvironment); }
GLuint OpenGLSurface::TextureYUV (int i) { if (!textureYUV[i]) { int j; GLSurface::TextureYUV (i); for (j = 0; j < 3; j++) { GLfloat border[][4] = { { 0.0625f, 0.0625f, 0.0625f, 0.0625f }, { 0.5f , 0.5f, 0.5f, 0.5f }, { 0.5f , 0.5f, 0.5f, 0.5f } }; glBindTexture (GL_TEXTURE_2D, textureYUV[j]); glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border[j]); } glBindTexture (GL_TEXTURE_2D, 0); } return textureYUV[i]; }
void piglit_init(int argc, char **argv) { GLubyte pixels[TEX_SIZE][TEX_SIZE][4]; GLuint tex; int i, j; piglit_require_gl_version(13); /* solid red texture */ for (i = 0; i < TEX_SIZE; i++) { for (j = 0; j < TEX_SIZE; j++) { pixels[i][j][0] = 255; pixels[i][j][1] = 0; pixels[i][j][2] = 0; pixels[i][j][3] = 255; } } glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_3D, tex); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER); glTexParameterfv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, green); glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glEnable(GL_TEXTURE_3D); }
bool Texture::loadFromFile(const char * filename, bool no_repeat) { glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, no_repeat ? GL_CLAMP_TO_BORDER : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, no_repeat ? GL_CLAMP_TO_BORDER : GL_REPEAT); if (no_repeat) { float border_color[] = { 0.0f, 0.0f, 0.0f, 0.0f }; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); unsigned char* image = SOIL_load_image(filename, &width, &height, 0, SOIL_LOAD_RGBA); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); glGenerateMipmap(GL_TEXTURE_2D); SOIL_free_image_data(image); glBindTexture(GL_TEXTURE_2D, 0); return true; }
void render(double t) { static const GLfloat green[] = { 0.0f, 0.1f, 0.0f, 1.0f }; static const GLfloat yellow[] = { 0.4f, 0.4f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, green); static const GLenum wrapmodes[] = { GL_CLAMP_TO_EDGE, GL_REPEAT, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT }; static const float offsets[] = { -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f }; glUseProgram(program); glViewport(0, 0, info.windowWidth, info.windowHeight); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, yellow); for (int i = 0; i < 4; i++) { glUniform2fv(0, 1, &offsets[i * 2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapmodes[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapmodes[i]); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } }
void Environment::createDL() { if((dlhandle == 0 || !glIsList(dlhandle)) && cubeMap.getUseAsDirectTextures()) { if(dlhandle == 0) dlhandle = glGenLists(1); glNewList(dlhandle, GL_COMPILE); { glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, environmentCubeVertices); if(texIDhandles.empty()) texIDhandles = cubeMap.getTextureIDs(); if(texIDhandles.size() > 0) { if(GLEW_VERSION_1_3) glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, environmentCubeTexCoords); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, nocolor); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); if(texIDhandles.size() == 1) { glBindTexture(GL_TEXTURE_2D, texIDhandles[0]); glDrawArrays(GL_QUADS, 0, 24); } else { glBindTexture(GL_TEXTURE_2D, texIDhandles[0]); glDrawArrays(GL_QUADS, 0, 4); glBindTexture(GL_TEXTURE_2D, texIDhandles[1]); glDrawArrays(GL_QUADS, 4, 4); glBindTexture(GL_TEXTURE_2D, texIDhandles[2]); glDrawArrays(GL_QUADS, 8, 4); glBindTexture(GL_TEXTURE_2D, texIDhandles[3]); glDrawArrays(GL_QUADS, 12, 4); glBindTexture(GL_TEXTURE_2D, texIDhandles[4]); glDrawArrays(GL_QUADS, 16, 4); glBindTexture(GL_TEXTURE_2D, texIDhandles[5]); glDrawArrays(GL_QUADS, 20, 4); } glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); } else glDrawArrays(GL_QUADS, 0, 24); glDisableClientState(GL_VERTEX_ARRAY); } glEndList(); } }
void SmokeRenderer::setLightColor(vec3f c) { m_lightColor = c; // set light texture border color GLfloat borderColor[4] = { 1.0 - m_lightColor[0], 1.0 - m_lightColor[1], 1.0 - m_lightColor[2], 0.0 }; glBindTexture(GL_TEXTURE_2D, m_lightTexture[0]); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glBindTexture(GL_TEXTURE_2D, m_lightTexture[1]); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glBindTexture(GL_TEXTURE_2D, 0); }
void shSetPatternTexGLState(SHPaint *p, VGContext *c) { glBindTexture(GL_TEXTURE_2D, ((SHImage*)p->pattern)->texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); switch(p->tilingMode) { case VG_TILE_FILL: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&c->tileFillColor); break; case VG_TILE_PAD: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); break; case VG_TILE_REPEAT: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); break; case VG_TILE_REFLECT: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); break; } glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor4f(1,1,1,1); }
void __glXDisp_TexParameterfv(GLbyte *pc) { glTexParameterfv( *(GLenum *)(pc + 0), *(GLenum *)(pc + 4), (GLfloat *)(pc + 8) ); }
void QOpenGLTextureHelper::qt_TextureParameterfv(GLuint texture, GLenum target, GLenum bindingTarget, GLenum pname, const GLfloat *params) { GLint oldTexture; glGetIntegerv(bindingTarget, &oldTexture); glBindTexture(target, texture); glTexParameterfv(target, pname, params); glBindTexture(target, oldTexture); }
void GLtexture::setBorderColor(const Rgba& color) { glBindTexture(GL_TEXTURE_2D, getObject()); Vector4 fcolor = color.toVector(); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, fcolor); }
void Texture2D::SetTextureBorderColor( const GLuint color /* = 0x0 */) { GLfloat colorf[4]; colorf[0] = (GLfloat)(color >> 24) / 255.0f; colorf[1] = (GLfloat)((color >> 16) & 255) / 255.0f; colorf[2] = (GLfloat)((color >> 8) & 255) / 255.0f; colorf[3] = 0.0f; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorf); }
void Texture::initRGBFile(const char* imgFile) { static GLubyte *texData; GLfloat borderColor[4] = { 1.0, 1.0, 1.0, 1.0 }; int width, height; int w, h; GLubyte *image, *img, *p; int i, j, components; image = (GLubyte *)read_rgb_texture(imgFile, &width, &height, &components); //w = width + 2 * 2; //h = height + 2 * 2; w = width; h = height; img = (GLubyte *)calloc(w * h, 4 * sizeof(unsigned char)); p = img; // for (j = -2; j < height + 2; ++j) { // for (i = -2; i < width + 2; ++i) { for (j = 0; j < height; ++j) { for (i = 0; i < width; ++i) { if (0 <= j && j <= height - 1 && 0 <= i && i <= width - 1) { p[0] = image[4 * (j * width + i) + 0]; p[1] = image[4 * (j * width + i) + 1]; p[2] = image[4 * (j * width + i) + 2]; p[3] = 0xff; } else { p[0] = borderColor[0] * 0xff; p[1] = borderColor[1] * 0xff; p[2] = borderColor[2] * 0xff; p[3] = borderColor[3] * 0xff; } p += 4; } } free(image); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, texture[0]); 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_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); //gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, // GL_RGBA, GL_UNSIGNED_BYTE, img); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img); glBindTexture(GL_TEXTURE_2D, 0); }
bool ccFrameBufferObject::initDepth(GLint wrapParam /*=GL_CLAMP_TO_BORDER*/, GLenum internalFormat /*=GL_DEPTH_COMPONENT24*/, GLint minMagFilter /*= GL_NEAREST*/, GLenum target/*=GL_TEXTURE_2D*/) { if (fboId==0) { //ccConsole::Warning("[FBO::initDepth] Internal error: FBO not yet initialized!"); return false; } start(); if (glIsTexture(depthTexture)) glDeleteTextures(1,&depthTexture); glGenTextures(1,&depthTexture); glBindTexture(target,depthTexture); /* INITIAL VERSION glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,width,height,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT,NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); //*/ float border[]={1.0,1.0,1.0,1.0}; glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapParam); glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapParam); glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, border); glTexParameteri(target, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_NONE); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minMagFilter); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, minMagFilter); glTexImage2D(target,0,internalFormat,width,height,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,0); //glFramebufferTextureEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,depthTexture,0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,target,depthTexture,0); glBindTexture(target, 0); bool success = false; GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); switch (status) { case GL_FRAMEBUFFER_COMPLETE_EXT: //ccConsole::Print("[FBO] Depth init. ok"); success = true; break; default: //ccConsole::Warning("[FBO] Depth texture init. error: %i",status); break; } stop(); return success; }
void RenderSystem::setTextureBorderColor( float r, float g, float b, float a ) { GLfloat border[] = {r, g, b, a}; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border); CROSS_GL_ASSERT(); }
bool CShadowHandler::InitDepthTarget() { // this can be enabled for debugging // it turns the shadow render buffer in a buffer with color bool useColorTexture = false; if (!fb.IsValid()) { LOG_L(L_ERROR, "[%s] framebuffer not valid", __FUNCTION__); return false; } glGenTextures(1, &shadowTexture); glBindTexture(GL_TEXTURE_2D, shadowTexture); float one[4] = {1.0f, 1.0f, 1.0f, 1.0f}; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, one); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if (useColorTexture) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, shadowMapSize, shadowMapSize, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); } else { const GLint texFormat = globalRendering->support24bitDepthBuffers ? GL_DEPTH_COMPONENT24 : GL_DEPTH_COMPONENT16; //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); glTexImage2D(GL_TEXTURE_2D, 0, texFormat, shadowMapSize, shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); } glGenTextures(1, &dummyColorTexture); if (globalRendering->atiHacks) { // ATI shadows fail without an attached color texture glBindTexture(GL_TEXTURE_2D, dummyColorTexture); // this dummy should be as small as possible not to waste memory glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA4, shadowMapSize, shadowMapSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL); } glBindTexture(GL_TEXTURE_2D, 0); fb.Bind(); if (useColorTexture) { fb.AttachTexture(shadowTexture); } else { if (globalRendering->atiHacks) fb.AttachTexture(dummyColorTexture); fb.AttachTexture(shadowTexture, GL_TEXTURE_2D, GL_DEPTH_ATTACHMENT_EXT); } const int buffer = (useColorTexture || globalRendering->atiHacks) ? GL_COLOR_ATTACHMENT0_EXT : GL_NONE; glDrawBuffer(buffer); glReadBuffer(buffer); const bool status = fb.CheckStatus("SHADOW"); fb.Unbind(); return status; }
void ATexture2D::bindTexture() { QImage timage,buf; if(!buf.load(m_fileName)) { qWarning("Could not read image file,using single-color instead"); QImage dummy(128,128,QImage::Format_RGB32); buf = dummy; } timage = QGLWidget::convertToGLFormat(buf); m_width = timage.width(); m_height = timage.height(); glGenTextures(1, &m_texID); //qDebug()<<"m_texID="<<m_texID; glBindTexture(GL_TEXTURE_2D, m_texID); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,timage.width(),timage.height(),0, GL_RGBA,GL_UNSIGNED_BYTE,timage.bits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); #ifdef GL_ES glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_NV); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_NV); #elseif glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); #endif float color[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; #ifdef GL_ES glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR_NV, color); #elseif glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color); #endif glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); //delete(&timage); //delete(&buf); }
EVA::Light::Light(const Type type, const bool shadows, const unsigned int shadowSize) { m_Type = type; m_Shadows = shadows; m_ShadowMapSize = shadowSize; if(!shadows) return;; if(m_Type == Directional) { glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_2D, m_DepthMap); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_ShadowMapSize, m_ShadowMapSize, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glGenFramebuffers(1, &m_DepthMapFb); glBindFramebuffer(GL_FRAMEBUFFER, m_DepthMapFb); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_DepthMap, 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glBindFramebuffer(GL_FRAMEBUFFER, 0); } else { glGenTextures(1, &m_DepthMap); glBindTexture(GL_TEXTURE_CUBE_MAP, m_DepthMap); for (unsigned int i = 0; i < 6; ++i) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, m_ShadowMapSize, m_ShadowMapSize, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glGenFramebuffers(1, &m_DepthMapFb); glBindFramebuffer(GL_FRAMEBUFFER, m_DepthMapFb); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
void Texture::Parameter::apply() const { for (const auto &pr : m_pari) { glTexParameteri(GL_TEXTURE_2D, pr.first, pr.second); } for (const auto &pr : m_parfv) { glTexParameterfv(GL_TEXTURE_2D, pr.first, pr.second); } }
static void _cg_texture_driver_try_setting_gl_border_color(cg_device_t *dev, GLuint gl_target, const GLfloat *transparent_color) { /* Use a transparent border color so that we can leave the color buffer alone when using texture co-ordinates outside of the texture */ GE(dev, glTexParameterfv(gl_target, GL_TEXTURE_BORDER_COLOR, transparent_color)); }
static void clear(GLuint t) { static const GLfloat p[] = { 0, 0, 0, 0 }; glBindTexture (GL_TEXTURE_2D, t); 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_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, p); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, p); }
//---------------------------------------------------- // Set kardane keyfiyat texture ha va address mode ha. //---------------------------------------------------- void RendererGL::SetTextureParams(TextureParams Params, int TextureStage) { glActiveTexture(GL_TEXTURE0 + TextureStage); switch (Params) { //*** F I L T E R I N G S case gfx::ETP_Point: glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); break; case gfx::ETP_Linear: glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR ); break; case gfx::ETP_Anisotropic: //check for hardware support if (!strstr((char*)glGetString(GL_EXTENSIONS),"GL_EXT_texture_filter_anisotropic")) { //get max ANISOTROPY and set it float maximumAnistropy; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnistropy); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maximumAnistropy); } break; //*** A D D R E S S I N G case gfx::ETP_Wrap: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); break; case gfx::ETP_BorderColor: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB); glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 0x00000000 ); break; case gfx::ETP_Clamp: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); break; case gfx::ETP_Mirror: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB); break; } } // SetTextureFilters