Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting BMP to texture help #3

Open
willos2006 opened this issue Jun 14, 2020 · 1 comment
Open

Converting BMP to texture help #3

willos2006 opened this issue Jun 14, 2020 · 1 comment

Comments

@willos2006
Copy link

Hello,

Sorry if this isn't the right place to ask. I'm new to all of openGL and i was wondering how i could take what comes back from your function and turn it into a texture.

Thanks for your help!

@vallentin
Copy link
Owner

No problem, feel free to ask here.

Here's a quick example I made, so there might be a typo or two. But this is how you'd load an image, create an OpenGL texture, and upload the image data to the texture.

unsigned char *pixels = NULL;
unsigned int width, height;

unsigned int err = loadbmp_decode_file("image.bmp", &pixels, &width, &height, LOADBMP_RGBA);

if (err) {
    printf("LoadBMP Load Error: %u\n", err);
} else {
    GLuint handle;
    glGenTextures(1, &handle);
    glBindTexture(GL_TEXTURE_2D, handle);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    //                                                        ^ must match loadbmp_decode_file

    free(pixels);
}

So if you use LOADBMP_RGBA then you ofc need to use GL_RGBA, and if LOADBMP_RGB then ofc GL_RGB.

If alpha is not needed, then you can change the internal format (the third argument) from GL_RGBA to GL_RGB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants