I am trying to load a bitmap to my openGL 3d object, however I get this error:
loadbitmap - bitcount failed = 8;
what I am trying to do is that I have an object and 3 separate bitmap images (Body, Eye, Head) bitmap images, so I`ll try to draw the texture till vector 6498, which are the triangles for the body part.
This error message isnt from the compiler it is printed manually from this file:
#ifndef _Bitmap_
#define _Bitmap_
#include "glad/glad.h"
#include <stdio.h>
#include <windows.h>
#include <wingdi.h>
GLuint loadbitmap(const char* filename, unsigned char*& pixelBuffer, BITMAPINFOHEADER* infoHeader, BITMAPFILEHEADER* fileHeader)
{
FILE* bitmapFile;
errno_t err = fopen_s(&bitmapFile, filename, "rb");
if (err != 0 || bitmapFile == NULL)
{
printf("loadbitmap - open failed for %s\n", filename);
return NULL;
}
fread(fileHeader, sizeof(BITMAPFILEHEADER), 1, bitmapFile);
if (fileHeader->bfType != 0x4D42)
{
printf("loadbitmap - type failed \n");
return NULL;
}
fread(infoHeader, sizeof(BITMAPINFOHEADER), 1, bitmapFile);
if (infoHeader->biBitCount < 24)
{
printf("loadbitmap - bitcount failed = %d\n", infoHeader->biBitCount);
return NULL;
}
fseek(bitmapFile, fileHeader->bfOffBits, SEEK_SET);
int nBytes = infoHeader->biWidth * infoHeader->biHeight * 3;
pixelBuffer = new unsigned char[nBytes];
fread(pixelBuffer, sizeof(unsigned char), nBytes, bitmapFile);
fclose(bitmapFile);
for (int i = 0; i < nBytes; i += 3)
{
unsigned char tmp = pixelBuffer[i];
pixelBuffer[i] = pixelBuffer[i + 2];
pixelBuffer[i + 2] = tmp;
}
printf("loadbitmap - loaded %s w=%d h=%d bits=%d\n", filename, infoHeader->biWidth, infoHeader->biHeight, infoHeader->biBitCount);
}
#endif
and I use this texture as follows:
GLuint texture = setup_texture("OBJFiles/Body.bmp");
glBindTexture(GL_TEXTURE_2D, texture);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 6498);
glBindVertexArray(0);