Textures, some work and some doesn't???

Started by
24 comments, last by babaliaris 5 years, 4 months ago

I tried both and they render okay.

Advertisement
Just now, stororokw said:

I tried both and they render okay.

Lol i also posted code from another project sorry (In my previous post)?

Anyways please try one more project : https://github.com/babaliaris/OpenGLTextureProblem

In this i have exactly prepared it correctly just for this problem. When i run it i get this:

Capture.png

What is your output?


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

I get this

lgl.png.163a9256912e5c21f38bc9263b001201.png

I also get a runtime error in shader.cpp line 56

lgl.png.0e4e9a031858753b580c39eb58bafdf2.png

10 minutes ago, stororokw said:

I get this

lgl.png.163a9256912e5c21f38bc9263b001201.png

I also get a runtime error in shader.cpp line 56

lgl.png.0e4e9a031858753b580c39eb58bafdf2.png

Well I don't get a Debug Error... But the texture is getting applied correctly on your computer. Ok one last thing :D . Can you run this pre build project (is the same one) and tell me again if you get an error and show me the output (It's build for windows 32)? Thank you very much for your help by the way.

You can download it from the following link.

https://mega.nz/#!gtUASSjI!sVT75RFlSfcspOmkPAn_7_CFotUSkarWU0UAdoG_XI0


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

Works fine on my computer. Looks the same as the screenshot i posted.

Just now, stororokw said:

Works fine on my computer. Looks the same as the screenshot i posted.

This leads me to one conclusion, it's amd's ati drivers fault. I'm not actually surprised i just wanted to be sure because the last past year amd had so many bugs in my graphics card series (AMD Radean R9 200 Series) and we where updating the drivers like every month. I also had dead lock problems at least 3 times per month (computer freezes and you have to restart it) but at least this was fixed. So yeah, it's probably the graphics drivers.

Thank you a lot for your help!!!


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

I don't know if anyone else mentioned it but an idea might to be either to view the texture in an OpenGL debugger after upload, or to read the pixels back. That way you can find out whether the problem is in the upload or the render.

8 minutes ago, lawnjelly said:

I don't know if anyone else mentioned it but an idea might to be either to view the texture in an OpenGL debugger after upload, or to read the pixels back. That way you can find out whether the problem is in the upload or the render.

I don't really know how to do that... Can you point me?


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

For the OpenGL debugger it's a good idea to have one installed for this and many such issues. I am not really up on which are good for windows so it is hard to recommend, but RenderDoc I have heard of, maybe that will work. For reading back manually, glReadPixels or glGetTexImage look like possibles (of course, you have to be careful your debugging texture reading code doesn't have errors! :) ).

Forcing stb_load to use 4 channels solved the problem but why the code below does not work?

What I'm doing is checking if division by 4 is an integer. If it's not an integer the do alignment by 1 else do alignment by 4.


Texture::Texture(std::string path, bool trans, int unit)
{

	//Reverse the pixels.
	stbi_set_flip_vertically_on_load(1);

	//Try to load the image.
	unsigned char *data = stbi_load(path.c_str(), &m_width, &m_height, &m_channels, 0);

	//If the size of each row is not divideable by 4
    // then use alignment of 1.
	float check = (m_width*m_channels) / 4.0f;
	if (check != ceilf(check))
	{
		std::cout << "working" << std::endl;
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	}
	
  	//If it is divideable by 4, use alignment of 4.
	else
		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

	//Image loaded successfully.
	if (data)
	{

		//Generate the texture and bind it.
		GLCall(glGenTextures(1, &m_id));
		GLCall(glActiveTexture(GL_TEXTURE0 + unit));
		GLCall(glBindTexture(GL_TEXTURE_2D, m_id));

		//Not Transparent texture.
		if (m_channels == 3)
		{
			GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, data));
		}

		//Transparent texture.
		else if (m_channels == 4)
		{
			GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data));
		}

		else
		{
			throw EngineError("UNSUPPORTEWD");
		}

		//Texture Filters.
		GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
		GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
		GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST));
		GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));

		//Generate mipmaps.
		GLCall(glGenerateMipmap(GL_TEXTURE_2D));
	}


	//Loading Failed.
	else
		throw EngineError("The was an error loading image: " + path);



	//Unbind the texture.
	GLCall(glBindTexture(GL_TEXTURE_2D, 0));

	//Free the image data.
	stbi_image_free(data);
}

 


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

This topic is closed to new replies.

Advertisement