Jump to content

  • Log In with Google      Sign In   
  • Create Account

Loading BMP but no color channels?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 D.V.D   Members   -  Reputation: 513

Like
0Likes
Like

Posted 01 September 2012 - 07:52 PM

So I'm following this tutorial: http://ogldev.atspace.co.uk/ and on tutorial 16, it shows me how to load textures and display them on triangles. I couldn't get their image library to work so I used my own that I found on the web that loads bitmap files. I have a VC project of it running just fine however on own project, it displays the bitmap correctly but without color just black and white O.o I tried to mimick the code and see if there where any differences that could cause this but Im stumped and can't find any. The main parts where I think all of this can be wrong are when I load the bmp into OpenGl so that I can use it (as the image loader itself works properly).

The texture class I created:

[source lang="cpp"]class Texture {public: Texture (GLenum TextureTarget, std::string FileName); bool Load_BMP (); void Bind (GLenum TextureUnit);private: std::string fileName; GLenum textureTarget; GLuint textureId; char* pixel_data;};[/source]

[source lang="cpp"]bool Texture::Load_BMP () { Image_BMP* TextureImg = loadBMP(fileName.c_str()); pixel_data = TextureImg->pixels; if ( pixel_data == NULL ) { delete TextureImg; return false; } glGenTextures(1, &textureId); glBindTexture(textureTarget, textureId); glTexImage2D(textureTarget, 0, GL_RGB, TextureImg->width, TextureImg->height, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImg->pixels); glTexParameterf(textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Min glTexParameterf(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Max delete TextureImg; return true;}void Texture::Bind (GLenum TextureUnit) { glActiveTexture(TextureUnit); glBindTexture(textureTarget, textureId);}[/source]
The render function for OpenGl:
The pipeline class and functions are for the camera.
[source lang="cpp"] pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT); static float Scale = 0.0f; Pipeline p; Scale += 0.1f; p.Rotate(0.0f, Scale, 0.0f); p.Translate(0.0f, 0.0f, 3.0f); p.SetCamera(pGameCamera->GetPos(), pGameCamera->GetTarget(), pGameCamera->GetUp()); p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 1.0f, 100.0f); glUniformMatrix4fv(gWVPLocation, 1, GL_TRUE, (const GLfloat*)p.GetTrans()); // Texture code starts here glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, VBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); pTexture->Bind(GL_TEXTURE0); glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glutSwapBuffers();[/source]

The texture is a global variable and is initialized in the main function:

[source lang="cpp"] pTexture = new Texture(GL_TEXTURE_2D, "test.bmp"); if ( !pTexture->Load_BMP() ) { return 1; }[/source]

Edited by D.V.D, 01 September 2012 - 07:57 PM.


Sponsor:

#2 D.V.D   Members   -  Reputation: 513

Like
0Likes
Like

Posted 01 September 2012 - 11:09 PM

So it seems that the entire code worked correctly but there was something up with the image file. What it is I don't know but paints 24bit bitmap doesn't seem to work well with this image loader.

#3 FXACE   Members   -  Reputation: 182

Like
0Likes
Like

Posted 02 September 2012 - 05:18 PM

Did you use shaders (if yes, post here what that shader does) or such things like "glEnable(GL_TEXTURE_2D)" at texture slot which was binded in?
Does this "Texture" class support for loading bmp files?

Edited by FXACE, 02 September 2012 - 05:23 PM.


#4 D.V.D   Members   -  Reputation: 513

Like
0Likes
Like

Posted 06 September 2012 - 06:19 AM

I used shaders i can'tpost them atm but it wasn't a problem with the shaders as the whole thing worked when i used a different bmp. It might be cause i used paint to convert not sure. I didn't use GL_ENABLE( 2D_TEXTURES) cause it wasn't mentioned in the tutorial. Other than the image file i can't find a different possibility for it not to work.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS