本文整理汇总了C++中Texture函数的典型用法代码示例。如果您正苦于以下问题:C++ Texture函数的具体用法?C++ Texture怎么用?C++ Texture使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Texture函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test
int test()
{
int Error(0);
gli::texture1d Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture1d::extent_type(4), 1);
*(Texture.data<glm::u8vec4>() + 0) = glm::u8vec4(255, 0, 0, 255);
*(Texture.data<glm::u8vec4>() + 1) = glm::u8vec4(255, 128, 0, 255);
*(Texture.data<glm::u8vec4>() + 2) = glm::u8vec4(255, 255, 0, 255);
*(Texture.data<glm::u8vec4>() + 3) = glm::u8vec4(128, 255, 0, 255);
glm::u8vec4 Data0 = Texture.load<glm::u8vec4>(gli::texture1d::extent_type(0), 0);
glm::u8vec4 Data1 = Texture.load<glm::u8vec4>(gli::texture1d::extent_type(1), 0);
glm::u8vec4 Data2 = Texture.load<glm::u8vec4>(gli::texture1d::extent_type(2), 0);
glm::u8vec4 Data3 = Texture.load<glm::u8vec4>(gli::texture1d::extent_type(3), 0);
Error += Data0 == glm::u8vec4(255, 0, 0, 255) ? 0 : 1;
Error += Data1 == glm::u8vec4(255, 128, 0, 255) ? 0 : 1;
Error += Data2 == glm::u8vec4(255, 255, 0, 255) ? 0 : 1;
Error += Data3 == glm::u8vec4(128, 255, 0, 255) ? 0 : 1;
return Error;
}
示例2: initTexture
bool initTexture()
{
gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
assert(!Texture.empty());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(texture::MAX, &TextureName[0]);
glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
glTexStorage2D(GL_TEXTURE_2D,
GLint(Texture.levels()),
GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
GLsizei(Texture.dimensions().x),
GLsizei(Texture.dimensions().y));
for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
{
glCompressedTexSubImage2D(
GL_TEXTURE_2D,
GLint(Level),
0, 0,
GLsizei(Texture[Level].dimensions().x),
GLsizei(Texture[Level].dimensions().y),
GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
GLsizei(Texture[Level].size()),
Texture[Level].data());
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
return true;
}
示例3: initTexture
bool initTexture()
{
bool Validated(true);
gli::gl GL;
gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
gli::gl::format const Format = GL.translate(Texture.format());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &TextureName);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Texture.levels()),
Format.Internal,
static_cast<GLsizei>(Texture[0].extent().x), static_cast<GLsizei>(Texture[0].extent().y), static_cast<GLsizei>(1));
for(gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level)
{
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Level),
0, 0, 0,
static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), GLsizei(1),
Format.External, Format.Type,
Texture[Level].data());
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
return Validated;
}
示例4: test_create_texture_storage
int test_create_texture_storage()
{
int Error(0);
gli::texture2D Texture(gli::FORMAT_RGBA8_UINT, gli::texture2D::dim_type(256));
gli::texture2D::size_type Levels = Texture.levels();
Error += Levels > 1 ? 0 : 1;
assert(!Texture.empty());
void const * Pointer = Texture[0].data();
Error += Pointer != 0 ? 0 : 1;
glm::u8vec4 TexelA = Texture[0].data<glm::u8vec4>()[0];
glm::u8vec4 TexelB = Texture[0].data<glm::u8vec4>()[1];
glm::u8vec4 TexelC = Texture[0].data<glm::u8vec4>()[2];
glm::u8vec4 TexelD = Texture[0].data<glm::u8vec4>()[3];
return Error;
}
示例5: parseMaterial
static void parseMaterial(){
_log( "Material" );
Brush mat;
string name,tex_name;
enterChunk();
while( int id=nextChunk() ){
switch( id ){
case CHUNK_MATNAME:
name=parseString();
break;
case CHUNK_DIFFUSE:
mat.setColor( parseColor() );
break;
case CHUNK_AMBIENT:
break;
case CHUNK_SPECULAR:
break;
case CHUNK_TEXTURE:
enterChunk();
while( int id=nextChunk() ){
switch( id ){
case CHUNK_MAPFILE:
tex_name=parseString();
break;
}
}
leaveChunk();
break;
}
}
if( tex_name.size() ){
mat.setTexture( 0,Texture( tex_name,0 ),0 );
mat.setColor( Vector( 1,1,1 ) );
}
if( name.size() ){
materials_map[name]=mat;
}
leaveChunk();
}
示例6: glGenTextures
const Texture& Pass::addOutputTexture(std::string name)
{
GLuint textureId;
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.getX(), m_size.getY(), 0, GL_RGBA, 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_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindFramebuffer(GL_FRAMEBUFFER, m_fboId);
glBindTexture(GL_TEXTURE_2D, textureId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + m_textures.size(), GL_TEXTURE_2D, textureId, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
m_textures.push_back(Texture(textureId, m_size, name));
return m_textures.back();
}
示例7: load_png
/// Loading a PNG file
gli::texture2D load_png(char const * Filename)
{
FreeImageInit();
FIBITMAP * Bitmap = FreeImage_Load(FIF_PNG, Filename, 0);
if(!Bitmap)
return gli::texture2D();
glm::uint BPP = FreeImage_GetBPP(Bitmap);
glm::uint Width = FreeImage_GetWidth(Bitmap);
glm::uint Height = FreeImage_GetHeight(Bitmap);
gli::texture2D Texture(1, BPP == 24 ? gli::RGB8_UNORM : gli::RGBA8_UNORM, gli::texture2D::dimensions_type(Width, Height));
memcpy(Texture.data(), FreeImage_GetBits(Bitmap), Texture.size());
FreeImage_Unload(Bitmap);
switch(gli::component_count(Texture.format()))
{
default:
assert(0);
break;
case 3:
for(std::size_t Offset = 0; Offset < Texture.size() / 3; ++Offset)
{
glm::u8vec3 Src = *(reinterpret_cast<glm::u8vec3 const *>(Texture.data()) + Offset);
*(reinterpret_cast<glm::u8vec3*>(Texture.data()) + Offset) = glm::u8vec3(Src.z, Src.y, Src.x);
}
break;
case 4:
for(std::size_t Offset = 0; Offset < Texture.size() / 4; ++Offset)
{
glm::u8vec4 Src = *(reinterpret_cast<glm::u8vec4 const *>(Texture.data()) + Offset);
*(reinterpret_cast<glm::u8vec4*>(Texture.data()) + Offset) = glm::u8vec4(Src.z, Src.y, Src.x, Src.w);
}
break;
}
return Texture;
}
示例8: Texture
void Player::setup(Vec2f pos){
player_texture = Texture("res/Texture/chara.png");
cut_y = 768;
fream = 12;
player.pos = pos;
player.size = Vec2f(95, 190);
speed = Vec2f(0.8, 21);
player.vec = Vec2f(0, 0);
g = 1;
selection = Vec2i(0, 0);
direction = DIRECTION::RIGHT;
ColorMax = 3;
color_abs = 0;
animation_count = 0;
dead_animation_count = 0;
clear_animation_count = 0;
dead_x = 0;
jump_flag = false;
}
示例9: decode_internal_attachment_offset
void GL3FrameBufferProvider::detach_object(GLenum opengl_attachment)
{
int internal_attachment_offset = decode_internal_attachment_offset(opengl_attachment);
GLenum target = GL_DRAW_FRAMEBUFFER;
if (bind_target == framebuffer_read)
target = GL_READ_FRAMEBUFFER;
if (!attached_renderbuffers[internal_attachment_offset].is_null())
{
glFramebufferRenderbuffer(target, opengl_attachment, GL_RENDERBUFFER, 0);
attached_renderbuffers[internal_attachment_offset] = RenderBuffer();
}
if (!attached_textures[internal_attachment_offset].is_null())
{
GL3TextureProvider *gl_texture_provider = dynamic_cast<GL3TextureProvider*>(attached_textures[internal_attachment_offset].get_provider());
GLuint texture_type = gl_texture_provider->get_texture_type();
if (texture_type == GL_TEXTURE_1D)
{
glFramebufferTexture1D(target, opengl_attachment, texture_type, 0, 0);
}
else if (texture_type == GL_TEXTURE_2D)
{
glFramebufferTexture2D(target, opengl_attachment, texture_type, 0, 0);
}
else if (texture_type == GL_TEXTURE_3D)
{
glFramebufferTexture3D(target, opengl_attachment, texture_type, 0, 0, 0);
}
else if (texture_type == GL_TEXTURE_2D_ARRAY || texture_type == GL_TEXTURE_1D_ARRAY)
{
glFramebufferTextureLayer(target, opengl_attachment, 0, 0, 0);
}
attached_textures[internal_attachment_offset] = Texture();
}
}
示例10: makeTexture
void makeTexture(){
texture = Texture(256, 1, Graphics::LUMINANCE_ALPHA, Graphics::UBYTE, true);
Array& sprite(texture.array());
struct{
uint8_t l, a;
}lum;
//texture fading out at the edges
for (size_t row = 0; row < sprite.height(); ++row) {
float y = float(row) / (sprite.height() - 1) * 2 - 1;
for (size_t col = 0; col < sprite.width(); ++col) {
float x = float(col) / (sprite.width() - 1) * 2 - 1;
// draw lightning, white in the center, and fades out toward the edges
// at two rates
if (abs(x) < 0.2)
lum.l = mapRange(abs(x), 0.f, .2f, 255.f, 60.f);
else
lum.l = mapRange(abs(x), 0.2f, 1.f, 60.f, 0.f);
lum.a = lum.l;
sprite.write(&lum.l, col, row);
}
}
}
示例11: initTexture
bool initTexture()
{
gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
assert(!Texture.empty());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &TextureName);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TextureName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
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_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level)
{
glTexImage2D(
GL_TEXTURE_2D,
GLint(Level),
GL_RGBA8,
GLsizei(Texture[Level].dimensions().x),
GLsizei(Texture[Level].dimensions().y),
0,
GL_BGR,
GL_UNSIGNED_BYTE,
Texture[Level].data());
}
if(Texture.levels() == 1)
glGenerateMipmap(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
return this->checkError("initTexture");
}
示例12: test
int test()
{
int Error = 0;
glm::u8vec4 const Black(0, 0, 0, 255);
glm::u8vec4 const Color(255, 127, 0, 255);
gli::texture3d Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture3d::extent_type(8), 5);
Texture.clear(Black);
glm::u8vec4 const TexelA = Texture.load<glm::u8vec4>(gli::texture3d::extent_type(0), 0);
glm::u8vec4 const TexelB = Texture.load<glm::u8vec4>(gli::texture3d::extent_type(0), 1);
glm::u8vec4 const TexelC = Texture.load<glm::u8vec4>(gli::texture3d::extent_type(0), 2);
Error += TexelA == Black ? 0 : 1;
Error += TexelB == Black ? 0 : 1;
Error += TexelC == Black ? 0 : 1;
Texture.clear<glm::u8vec4>(1, glm::u8vec4(255, 127, 0, 255));
gli::texture3d::extent_type Coords(0);
for(; Coords.z < Texture.extent(1).z; ++Coords.z)
for(; Coords.y < Texture.extent(1).y; ++Coords.y)
for(; Coords.x < Texture.extent(1).x; ++Coords.x)
{
glm::u8vec4 const TexelD = Texture.load<glm::u8vec4>(Coords, 1);
Error += TexelD == Color ? 0 : 1;
}
gli::texture3d TextureView(Texture, 1, 1);
gli::texture3d TextureImage(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture3d::extent_type(4), 1);
TextureImage.clear(Color);
Error += TextureView == TextureImage ? 0 : 1;
return Error;
}
示例13: initTexture
bool initTexture()
{
gli::gl GL(gli::gl::PROFILE_GL32);
gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
assert(!Texture.empty());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &TextureName);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TextureName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
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_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles());
for(gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level)
{
glTexImage2D(GL_TEXTURE_2D, GLint(Level),
Format.Internal,
GLsizei(Texture[Level].extent().x),
GLsizei(Texture[Level].extent().y),
0,
Format.External, Format.Type,
Texture[Level].data());
}
if(Texture.levels() == 1)
glGenerateMipmap(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
return this->checkError("initTexture");
}
示例14: loadTex
GLuint loadTex(std::string filename) {
gli::texture2D Texture(gli::loadStorageDDS(filename));
GLuint TextureName;
glGenTextures(1, &TextureName);
assert(!Texture.empty());
glBindTexture(GL_TEXTURE_2D, TextureName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGB8,
GLsizei(Texture[0].dimensions().x),
GLsizei(Texture[0].dimensions().y),
0,
GL_BGRA,
GL_UNSIGNED_BYTE,
Texture[0].data());
return TextureName;
}
示例15: defaultTexture
void Scene::Init(CoreEngine* _engine) {
_engine->physicsEnabled = true; // Enable engine physics upon startup
renderer = _engine->renderer;
// Create default Materials
Material defaultTexture("default_texture", Texture("default_texture.png"), NULL, 0.0f, 20.0f, NULL, NULL, 0.03f, -0.5f);
// Set up main camera
GameObject* mainCamera = new GameObject("Main Camera");
mainCamera->transform.isSelectable = false;
mainCamera->transform.position = vec3(10, 15, 15);
mainCamera->transform.LookAt(vec3(0));
Camera::current = mainCamera->AddComponent<Camera>(Camera((float)Window::width / (float)Window::height, 75.0f));
mainCamera->AddComponent<FlyCameraScript>();
AddToScene(mainCamera);
// Set up directional light
GameObject* directionalLight = new GameObject("Directional Light");
directionalLight->transform.isSelectable = false;
directionalLight->transform.position = vec3(0,0,0);
directionalLight->AddComponent<DirectionalLight>();
AddToScene(directionalLight);
}