Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Johnn

Drawing images in 2d

This topic is 5300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the interface of my game, I want to draw images in 2d. I dont want to texture quads... So using a LoadBitmapFile function from opengl game programming book and DrawBitmap() I got my first image drawn. The thing is, it looks weird - I cant even reconize the original image. The image is a 32x32 24 bit bmp made in photoshop. Any ideas why its like that?
BITMAPINFOHEADER	imMenuCursorHeader;
unsigned char*		imMenuCursor;

//...

DrawBitmap(imMenuCursorHeader.biWidth, imMenuCursorHeader.biHeight, 220, SCREEN_HEIGHT/2, imMenuCursor);

//...

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
	FILE *filePtr;								
	BITMAPFILEHEADER	bitmapFileHeader;	
	unsigned char		*bitmapImage;		
	int					imageIdx = 0;		
	unsigned char		tempRGB;			

	filePtr = fopen(filename, "rb");
	if (filePtr == NULL)
		return NULL;

	fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

	if (bitmapFileHeader.bfType != BITMAP_ID)
	{
		fclose(filePtr);
		return NULL;
	}

	fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

	fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

	bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);

	if (!bitmapImage)
	{
		free(bitmapImage);
		fclose(filePtr);
		return NULL;
	}

	fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);

	if (bitmapImage == NULL)
	{
		fclose(filePtr);
		return NULL;
	}

	for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
	{
		tempRGB = bitmapImage[imageIdx];
		bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
		bitmapImage[imageIdx + 2] = tempRGB;
	}

	fclose(filePtr);
	return bitmapImage;
}


void DrawBitmap(long width, long height, int posX, int posY, unsigned char* bitmapImage)
{
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	glRasterPos2i(posX, posY);
	glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, bitmapImage);
}
 

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!