Ejemplo n.º 1
0
	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;
	}
	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;
	}
Ejemplo n.º 3
0
	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;
	}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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();
}
Ejemplo n.º 6
0
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();
}
Ejemplo n.º 7
0
/// 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;
}
Ejemplo n.º 8
0
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;
}
	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();
		}
	}
Ejemplo n.º 10
0
 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);
     }
   }
 }
	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");
	}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
bool initTexture()
{
    bool Validated(true);

    gli::texture2D Texture(gli::loadStorageDDS(glf::DATA_DIRECTORY + TEXTURE_DIFFUSE));

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glGenTextures(1, &TextureName);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, TextureName);
    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);
    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_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), GL_RGBA8, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y));

    for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level)
    {
        glTexSubImage2D(
            GL_TEXTURE_2D,
            GLint(Level),
            0, 0,
            GLsizei(Texture[Level].dimensions().x),
            GLsizei(Texture[Level].dimensions().y),
            GL_BGR, GL_UNSIGNED_BYTE,
            Texture[Level].data());
    }

    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

    return Validated;
}
	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");
	}
Ejemplo n.º 15
0
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;
}
Ejemplo n.º 16
0
	int test()
	{
		int Error = 0;

		{
			gli::texture1d Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture1d::extent_type(8), 1);
			Texture.clear(gli::u8vec4(0, 127, 255, 255));
			Texture.store(gli::texture1d::extent_type(0), 0, gli::u8vec4(255, 127,   0, 255));
			Texture.store(gli::texture1d::extent_type(1), 0, gli::u8vec4(255, 127,   0, 255));
			Texture.store(gli::texture1d::extent_type(2), 0, gli::u8vec4(255, 127,   0, 255));
			Texture.store(gli::texture1d::extent_type(3), 0, gli::u8vec4(255, 127,   0, 255));

			gli::fsampler1D const Sampler(Texture, gli::WRAP_CLAMP_TO_EDGE, gli::FILTER_LINEAR, gli::FILTER_LINEAR);

			gli::vec4 SampleA = Sampler.texture_lod(gli::fsampler1D::normalized_type(0.25f), 0.0f);
			Error += gli::all(gli::epsilonEqual(SampleA, gli::vec4(1.0f, 0.5f, 0.0f, 1.0f), 0.01f)) ? 0 : 1;

			gli::vec4 SampleB = Sampler.texture_lod(gli::fsampler1D::normalized_type(0.75f), 0.0f);
			Error += gli::all(gli::epsilonEqual(SampleB, gli::vec4(0.0f, 0.5f, 1.0f, 1.0f), 0.01f)) ? 0 : 1;
		}

		return Error;
	}
Ejemplo n.º 17
0
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);
}
Ejemplo n.º 18
0
bool initTexture()
{
	glGenTextures(1, &TextureName);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, TextureName);

	gli::texture2D Texture(gli::loadStorageDDS(glf::DATA_DIRECTORY + TEXTURE_DIFFUSE_DXT5));
	for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
	{
		glCompressedTexImage2D(
			GL_TEXTURE_2D,
			GLint(Level),
			GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
			GLsizei(Texture[Level].dimensions().x), 
			GLsizei(Texture[Level].dimensions().y), 
			0, 
			GLsizei(Texture[Level].size()), 
			Texture[Level].data());
	}

	return glf::checkError("initTexture");
}
Ejemplo n.º 19
0
void StageSelect::loadRes() {
	std::string texturepass = "******";
	window_tex_ = Texture(texturepass + "Window_UI.png");
	background_tex_ = Texture(texturepass + "StageSelect_UI.png");
	mouse_tex_ = Texture(texturepass + "MouseP_UI.png");
	scroll_tex_ = Texture(texturepass + "Scroll_UI.png");
	scrollbar_tex_ = Texture(texturepass + "ScrollBar_UI.png");
	dodai_tex_ = Texture(texturepass + "dodai.png");

	std::string bgmpass = "******";
	bgm_ = Media(bgmpass);

	std::string sepass = "******";
	mouse_se_ = Media(sepass + "MovingCursol.wav");
	start_se_ = Media(sepass + "GameStart.wav");
	cyancel_se_ = Media(sepass + "Cansel.wav");
	select_se_ = Media(sepass + "Select.wav");
}
Ejemplo n.º 20
0
void Framebuffer::setupFramebufferTexture(GLuint format, float up_sample) {
    // Create texture for framebuffer (should probably be a constructor in texture)
    GLuint texture_id;
    glGenTextures(1, &texture_id);
    glBindTexture(GL_TEXTURE_2D, texture_id);

    this->width = up_sample * Window::getInstance()->getWidth();
    this->height = up_sample * Window::getInstance()->getHeight();

    glTexImage2D(GL_TEXTURE_2D, 0, format, this->width, this->height, 0, format,
        GL_UNSIGNED_BYTE, 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);

    framebuffer_texture = Texture(texture_id);

    //  Bind framebuffer and link texture to it
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
        framebuffer_texture.getGLId(), 0);
}
	bool initTexture()
	{
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		if(Texture.empty())
			return false;

		gli::gl GL;
		gli::gl::format const Format = GL.translate(Texture.format());

		glCreateTextures(GL_TEXTURE_2D, 1, &TextureName[texture::TEXTURE]);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTextureStorage2D(TextureName[texture::TEXTURE], GLint(Texture.levels()), Format.Internal, GLsizei(Texture[0].extent().x), GLsizei(Texture[0].extent().y));
		for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
		{
			glTextureSubImage2D(TextureName[texture::TEXTURE], GLint(Level),
				0, 0, 
				GLsizei(Texture[Level].extent().x), GLsizei(Texture[Level].extent().y),
				Format.External, Format.Type,
				Texture[Level].data());
		}

		glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &TextureName[texture::MULTISAMPLE]);
		glTextureParameteri(TextureName[texture::MULTISAMPLE], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::MULTISAMPLE], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2DMultisample(TextureName[texture::MULTISAMPLE], 4, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_FALSE);

		glCreateTextures(GL_TEXTURE_2D, 1, &TextureName[texture::COLORBUFFER]);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2D(TextureName[texture::COLORBUFFER], 1, GL_RGBA8, GLsizei(FRAMEBUFFER_SIZE.x), GLsizei(FRAMEBUFFER_SIZE.y));

		return true;
	}
	int test(gli::format Format, genType const & Black, genType const & Color, std::size_t Layers, std::size_t Size, gli::filter Filter)
	{
		int Error = 0;

		gli::texture_cube_array Texture(Format, gli::texture_cube_array::extent_type(static_cast<gli::texture_cube_array::extent_type::value_type>(Size)), Layers);
		Texture.clear(Black);
		for(std::size_t Layer = 0; Layer < Layers; ++Layer)
		for(std::size_t Face = 0; Face < 6; ++Face)
			Texture[Layer][Face][0].clear(Color);

		for(std::size_t Layer = 0; Layer < Layers; ++Layer)
		for(std::size_t Face = 0; Face < 6; ++Face)
		{
			genType const LoadC = Texture.load<genType>(gli::texture_cube_array::extent_type(0), Layer, Face, Texture.max_level());
			if(Texture.levels() > 1)
				Error += LoadC == Black ? 0 : 1;

			gli::fsamplerCubeArray SamplerA(gli::texture_cube_array(gli::duplicate(Texture)), gli::WRAP_CLAMP_TO_EDGE);
			SamplerA.generate_mipmaps(gli::FILTER_LINEAR);

			gli::texture_cube_array MipmapsA = SamplerA();
			genType const LoadA = MipmapsA.load<genType>(gli::texture_cube_array::extent_type(0), Layer, Face, MipmapsA.max_level());
			Error += LoadA == Color ? 0 : 1;
			if(Texture.levels() > 1)
				Error += LoadA != LoadC ? 0 : 1;

			// Mipmaps generation using the wrapper function
			gli::texture_cube_array MipmapsB = gli::generate_mipmaps(gli::texture_cube_array(gli::duplicate(Texture)), Filter);
			genType const LoadB = MipmapsB.load<genType>(gli::texture_cube_array::extent_type(0), Layer, Face, MipmapsB.max_level());
			Error += LoadB == Color ? 0 : 1;
			if(Texture.levels() > 1)
				Error += LoadB != LoadC ? 0 : 1;
		}

		return Error;
	}
Ejemplo n.º 23
0
	bool initTexture()
	{
		glGenTextures(texture::MAX, &TextureName[0]);

		gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
		{
			glTexImage2D(
				GL_TEXTURE_2D, 
				GLint(Level), 
				GL_RGB8, 
				GLsizei(Texture[Level].dimensions().x), 
				GLsizei(Texture[Level].dimensions().y), 
				0,
				GL_BGR, 
				GL_UNSIGNED_BYTE, 
				Texture[Level].data());
		}

		glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glBindTexture(GL_TEXTURE_2D, 0);

		glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, TextureName[texture::MULTISAMPLE]);
		glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 8, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_TRUE); // The second parameter is the number of samples.
		glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);

		return this->checkError("initTexture");
	}
Ejemplo n.º 24
0
        Cell(sf::Vector2f position, Size type, int startValue = 0) : Element(Texture("cellule.png"), position, 0.f)
        {
            value = startValue;
            setOrigin(250, 250);

            radius = (type==BIG ? 100 : (type==MED ? 75 : 50));

            float scale = 2.f*radius/sprite.getLocalBounds().width;
            setScale(scale, scale);


            genRate = (type==BIG ? 3 : (type==MED ? 2 : 1));

            valueText.setFont(Font("pixelart.ttf"));
            valueText.setCharacterSize(24);
            valueText.setString("00");
            valueText.setOrigin(valueText.getGlobalBounds().width/2.f, valueText.getGlobalBounds().height/2.f);
            valueText.setPosition(position);
            valueText.setColor(sf::Color::White);

			setColor(sf::Color(200,200,200));

			lastAttack = 0;
        }
Ejemplo n.º 25
0
	int run()
	{
		int Error(0);

		std::vector<test> Tests;
		Tests.push_back(test(gli::FORMAT_RGBA8_UINT_PACK8, gli::texture::extent_type(1), 4));
		Tests.push_back(test(gli::FORMAT_R8_UINT_PACK8, gli::texture::extent_type(1), 1));

		for(std::size_t i = 0; i < Tests.size(); ++i)
		{
			gli::texture Texture(
				gli::TARGET_2D,
				Tests[i].Format,
				gli::texture::extent_type(1),
				gli::texture::size_type(1),
				gli::texture::size_type(1),
				gli::texture::size_type(1));

			Error += Texture.size() == Tests[i].Size ? 0 : 1;
			GLI_ASSERT(!Error);
		}

		return Error;
	}
Ejemplo n.º 26
0
void ForwardDirectional::UpdateUniforms(const mat4& modelMatrix, const Material& material)
{
	static Texture WHITE = Texture(1, 1, whitePixel);

	if (material.GetTexture() != NULL)
		material.GetTexture()->Bind(0);
	else
	{
		WHITE.Bind(0);
	}
	mat4 MVP = GetRenderEngine()->GetCamera()->GetProjectionMatrix() * GetRenderEngine()->GetCamera()->GetViewMatrix() * modelMatrix;

	SetUniform("MVP", MVP);
	SetUniform("ModelMatrix", modelMatrix);
	SetUniform("NormalMatrix", glm::inverseTranspose(mat3(modelMatrix)));

	SetUniform("directionalLight.direction", static_cast<DirectionalLight*>(GetRenderEngine()->GetActiveLight())->GetDirection());
	SetUniform("directionalLight.base.color", static_cast<DirectionalLight*>(GetRenderEngine()->GetActiveLight())->GetColor());
	SetUniform("directionalLight.base.intensity", static_cast<DirectionalLight*>(GetRenderEngine()->GetActiveLight())->GetIntensity());

	SetUniform("specularIntensity", material.GetSpecularIntensity());
	SetUniform("specularPower", material.GetSpecularPower());
	SetUniform("eyePosition", GetRenderEngine()->GetCamera()->GetPosition());
}
Ejemplo n.º 27
0
    int run()
    {
        int Error(0);

        std::vector<test> Tests;
        Tests.push_back(test(gli::RGBA8U, gli::texture1D::dimensions_type(4), 16));
        Tests.push_back(test(gli::R8U, gli::texture1D::dimensions_type(4), 4));

        for(std::size_t i = 0; i < Tests.size(); ++i)
        {
            gli::texture1D Texture(
                gli::texture1D::size_type(1),
                Tests[i].Format,
                gli::texture1D::dimensions_type(4));

            gli::image Image = Texture[0];

            Error += Image.size() == Tests[i].Size ? 0 : 1;
            Error += Texture.size() == Tests[i].Size ? 0 : 1;
            assert(!Error);
        }

        return Error;
    }
Ejemplo n.º 28
0
CommonGUIStyle::CommonGUIStyle(class OpenGL* gl)
{
	auto LoadTexture = [&](const String& path)
	{
		String fullPath = Path::Normalize(String("textures/ui/") + path);
		Image img = ImageRes::Create(fullPath);
		if(!img)
			return Texture();
		return TextureRes::Create(gl, img);
	};

	buttonTexture = LoadTexture("button.png");
	buttonHighlightTexture = LoadTexture("button_hl.png");
	buttonPadding = Margini(10);
	buttonBorder = Margini(5);

	sliderButtonTexture = LoadTexture("slider_button.png");
	sliderButtonHighlightTexture = LoadTexture("slider_button_hl.png");
	sliderTexture = LoadTexture("slider.png");
	sliderBorder = Margini(8, 0);
	sliderButtonPadding = Margini(-15, -8);

	verticalSliderButtonTexture = LoadTexture("vslider_button.png");
	verticalSliderButtonHighlightTexture = LoadTexture("vslider_button_hl.png");
	verticalSliderTexture = LoadTexture("vslider.png");
	verticalSliderBorder = Margini(0, 8);
	verticalSliderButtonPadding = Margini(-8, -15);

	textfieldTexture = LoadTexture("textfield.png");
	textfieldHighlightTexture = LoadTexture("textfield_hl.png");
	textfieldPadding = Margini(10);
	textfieldBorder = Margini(5);

	spinnerTexture = LoadTexture("spinner.png");
	spinnerTexture->SetWrap(TextureWrap::Clamp, TextureWrap::Clamp);
}
Ejemplo n.º 29
0
int test_texture1DArray_query()
{
	int Error(0);

	gli::texture1DArray::size_type Layers(2);
	gli::texture1DArray::size_type Levels(2);

	gli::texture1DArray Texture(
		Layers, 
		Levels,
		gli::RGBA8U,
		gli::texture1DArray::dimensions_type(2));

	gli::texture1DArray::size_type Size = Texture.size();

	Error += Size == sizeof(glm::u8vec4) * 3 * Layers ? 0 : 1;
	Error += Texture.format() == gli::RGBA8U ? 0 : 1;
	Error += Texture.layers() == Layers ? 0 : 1;
	Error += Texture.levels() == Levels ? 0 : 1;
	Error += !Texture.empty() ? 0 : 1;
	Error += Texture.dimensions() == 2 ? 0 : 1;

	return Error;
}
Ejemplo n.º 30
0
	bool initTexture()
	{
		gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		gli::gl GL;

		glGenTextures(texture::MAX, &TextureName[0]);
		glActiveTexture(GL_TEXTURE0);
		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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

		gli::gl::format const Format = GL.translate(Texture.format());
		for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
		{
			glTexImage2D(GL_TEXTURE_2D, GLint(Level),
				Format.Internal,
				GLsizei(Texture[Level].dimensions().x), GLsizei(Texture[Level].dimensions().y),
				0,
				Format.External, Format.Type,
				Texture[Level].data());
		}
		glGenerateMipmap(GL_TEXTURE_2D); // Allocate all mipmaps memory

		glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

		glBindTexture(GL_TEXTURE_2D, 0);

		return true;
	}