Пример #1
0
void Material::setMaterialTexture(unsigned int layer, const char *textureFile) {
  if (layer < TEX_LAYER_COUNT) {
    if (loadTextureData(textureFile, mTexture[layer])) {
      if (layer < NORMAL_TEX) {
        mMaterialComponentEnabled[layer + 1] = true;
      }
      mUniformsInitialized = false;
    }
  }
}
Пример #2
0
unsigned char* loadPixels(const char *filename, gDisplay *d) {
  texture* tex;
  /* load a texture, scale it to the appropriate size */
  tex = loadTextureData(filename);
  return scalePixels(tex->data, 
		     tex->width, tex->height,
		     0, 0,
		     tex->width, tex->height,
		     d->vp_w, d->vp_h, 
		     tex->channels);
}
Пример #3
0
void loadTexture(const char *path, int format) {
	png_texture *tex;
	GLint internal;
	int maxSize;

	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);

	tex = loadTextureData(path);
	if(tex->channels == 3)
		internal = GL_RGB;
	else
		internal = GL_RGBA;
	if(format == GL_DONT_CARE)
	{
		if(tex->channels == 3) format = GL_RGB;
		if(tex->channels == 4) format = GL_RGBA;
	}
	/* TODO: build mipmaps the proper way, box filters suck */
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	{
		png_texture *newtex;
		int level = 0;
		while (tex->width > 1 || tex->height > 1)
		{
			if(tex->width <= maxSize && tex->height <= maxSize)
			{
				glTexImage2D(GL_TEXTURE_2D, level, format, 
					 tex->width, tex->height,
					 0, internal, GL_UNSIGNED_BYTE, tex->data);
#ifdef PRINTF_VERBOSE
				printf("uploading level %d, %dx%d texture\n", 
					 level, tex->width, tex->height);
#endif
				level++;
			}
			newtex = mipmap_png_texture(tex, 1, 0, 0);
			freeTextureData(tex);
			tex = newtex;
		}
		/* upload 1x1 mip level */
		glTexImage2D(GL_TEXTURE_2D, level, format, 
			 tex->width, tex->height,
			 0, internal, GL_UNSIGNED_BYTE, tex->data);
#ifdef PRINTF_VERBOSE
		printf("uploading level %d, %dx%d texture\n", 
			level, tex->width, tex->height);
#endif
		freeTextureData(tex);
	}
}
Пример #4
0
void MenuState::createTexture()
{
    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1, &m_Texture);
    glBindTexture(GL_TEXTURE_2D, m_Texture);

    setTextureWrapping();
    setTextureFiltering();

    glGenerateMipmap(GL_TEXTURE_2D);

    auto textureData = loadTextureData();

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_TextureWidth, m_TextureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData);

    SOIL_free_image_data(textureData);
}
Пример #5
0
	void SceneImporter::loadScene(unsigned int entityId, const char* scenePath, std::string shader)
	{
		//Import Scene
		mScene = mImporter->ReadFile(scenePath,
			aiProcess_Triangulate |
			aiProcess_GenSmoothNormals |
			aiProcess_JoinIdenticalVertices |
			aiProcess_ImproveCacheLocality |
			aiProcess_CalcTangentSpace |
			aiProcess_OptimizeMeshes |
			aiProcess_OptimizeGraph);


		//Load each mesh
		for (unsigned int i = 0; i < mScene->mNumMeshes; ++i)
		{
			component::MeshComponent* meshComponent = mEntityWorld->getMeshWorld().add(entityId);
			assert(meshComponent);

			aiMesh* mesh = mScene->mMeshes[i];
			assert(mesh);
			aiMaterial* material = mScene->mMaterials[mesh->mMaterialIndex];
			assert(material);
			Material* newMaterial = new Material();
			newMaterial->shader = mShaderLoader->load(shader);

			loadVertexData(mesh, meshComponent->vertices, meshComponent->indices);

			if (mesh->HasTextureCoords(0))
			{
				loadTextureData(mesh, material, newMaterial);
			}

			if (!loadMaterialProperties(material, newMaterial))
			{
				std::cerr << "SceneImporter: Error loading material properties for: " << scenePath << std::endl;
			}

			meshComponent->material = newMaterial;
		}
	}
Пример #6
0
Файл: Ex07.cpp Проект: Aegyr/cg2
void initTextures (void) {
	// generate a new OpenGL texture
	glGenTextures(1, &texture);

	// initialize the texture properly (filtering, wrapping style, etc.)
	glBindTexture(GL_TEXTURE_2D, texture);
	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_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	// "../textures/trashbin.png" OR "../textures/ball.jpg"
	TextureData texturedata = loadTextureData("../textures/trashbin.png");
	//TextureData texturedata = loadTextureData("../textures/ball.jpg");

	// upload the imported image data to the OpenGL texture
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texturedata.width, texturedata.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texturedata.data);

	// don't forget to clean up
	glBindTexture(GL_TEXTURE_2D, 0);
	delete[] texturedata.data;
}