Thread: DrawIndexedPrimitive() Failing (DX9)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    It's all making sense now

    You're right about the padding, however, I don't think there's an Alpha channel. I've been using a 2x2 bitmap until now:
    192 192 192 192 | 192 192 0 0 |
    192 192 192 192 | 192 192 0 0 |
    From above.

    Which is making sense for the padding:
    R G B R | G B PAD PAD |
    R G B R | G B PAD PAD |
    Where the PADs are the 0s, and you get the lovely Width multiple of 4 thing.

    I switched to a 4x4 bitmap, with R = 100, G = 150, and B = 200, and got the output:
    Opening File: Succeeded
    File Status: Valid
    Creating Pixels: Succeeded

    | 200 150 100 | 200 150 100 | 200 150 100 | 200 150 100
    | 200 150 100 | 200 150 100 | 200 150 100 | 200 150 100
    | 200 150 100 | 200 150 100 | 200 150 100 | 200 150 100
    | 200 150 100 | 200 150 100 | 200 150 100 | 200 150 100
    Press any key to continue
    Integer then Hex printed out

    And the larger images aren't going haywire near the end.

    Here is the sourcecode for my current loader:
    Code:
    #include <Stdlib.h>
    #include <Stdio.h>
    
    #define INPUT_PATH "C:\\4.bmp"
    
    struct CUSTOMBITMAPHEADER
    {
    	unsigned short	Type;
    	unsigned long	Size;
    	unsigned short	Reserved1;
    	unsigned short	Reserved2;
    	unsigned long	OffBits;
    	unsigned long	RemainingSize;
    	unsigned long	Width;
    	unsigned long	Height;
    	unsigned short	Planes;
    	unsigned short	BitCount;
    	unsigned long	Compression;
    	unsigned long	SizeImage;
    	unsigned long	XPelsPerMeter;
    	unsigned long	YPelsPerMeter;
    	unsigned long	ClrUsed;
    	unsigned long	ClrImportant;
    };
    
    void CompleteHeader(CUSTOMBITMAPHEADER *BitmapHeader, FILE *BinaryIFile);
    
    int main(void)
    {
    	CUSTOMBITMAPHEADER CustomBitmapHeader;
    	unsigned char *Pixels = NULL;
    
    	FILE *InputFile = NULL;
    	unsigned long	FileSize = 0;
    
    	printf("Opening File: ");
    	InputFile = fopen(INPUT_PATH, "rb");
    	if(InputFile == NULL)
    	{
    		printf("Failed\n");
    	}
    	else
    	{
    		printf("Succeeded\n");
    
    		fseek(InputFile, 0, SEEK_END);
    		FileSize = ftell(InputFile);
    		rewind(InputFile);
    
    		printf("File Status: ");
    		if(FileSize < sizeof(CUSTOMBITMAPHEADER))
    		{
    			printf("Invalid\n");
    		}
    		else
    		{
    			printf("Valid\n");
    			
    			CompleteHeader(&CustomBitmapHeader, InputFile);
    
    			printf("Creating Pixels: ");
    			Pixels = (unsigned char *)malloc(CustomBitmapHeader.SizeImage);
    			if(Pixels == NULL)
    			{
    				printf("Failed\n");
    			}
    			else
    			{
    				printf("Succeeded\n");
    
    				fread(&(Pixels[0]), sizeof(Pixels[0]), 1, InputFile);
    				for(int I = 0; feof(InputFile) == false; I++)
    				{
    					if(I % (CustomBitmapHeader.Width * 3) == 0)
    						printf("\n");
    
    					if(I % 3 == 0)
    						printf("| ");
    
    					printf("%d ", Pixels[I]);
    					fread(&(Pixels[I+1]), sizeof(Pixels[I+1]), 1, InputFile);
    				}
    				printf("\n");
    			}
    		}
    	}
    
    	if(Pixels != NULL)
    	{
    		free(Pixels);
    		Pixels = NULL;
    	}
    
    	if(InputFile != NULL)
    	{
    		fclose(InputFile);
    		InputFile = NULL;
    	}
    
    	return 0;
    }
    
    void CompleteHeader(CUSTOMBITMAPHEADER *BitmapHeader, FILE *BinaryIFile)
    {
    	fread(&(BitmapHeader->Type), sizeof(BitmapHeader->Type), 1, BinaryIFile);
    	fread(&(BitmapHeader->Size), sizeof(BitmapHeader->Size), 1, BinaryIFile);
    	fread(&(BitmapHeader->Reserved1), sizeof(BitmapHeader->Reserved1), 1, BinaryIFile);
    	fread(&(BitmapHeader->Reserved2), sizeof(BitmapHeader->Reserved2), 1, BinaryIFile);
    	fread(&(BitmapHeader->OffBits), sizeof(BitmapHeader->OffBits), 1, BinaryIFile);
    	fread(&(BitmapHeader->RemainingSize), sizeof(BitmapHeader->Size), 1, BinaryIFile);
    	fread(&(BitmapHeader->Width), sizeof(BitmapHeader->Width), 1, BinaryIFile);
    	fread(&(BitmapHeader->Height), sizeof(BitmapHeader->Height), 1, BinaryIFile);
    	fread(&(BitmapHeader->Planes), sizeof(BitmapHeader->Planes), 1, BinaryIFile);
    	fread(&(BitmapHeader->BitCount), sizeof(BitmapHeader->BitCount), 1, BinaryIFile);
    	fread(&(BitmapHeader->Compression), sizeof(BitmapHeader->Compression), 1, BinaryIFile);
    	fread(&(BitmapHeader->SizeImage), sizeof(BitmapHeader->SizeImage), 1, BinaryIFile);
    	fread(&(BitmapHeader->XPelsPerMeter), sizeof(BitmapHeader->XPelsPerMeter), 1, BinaryIFile);
    	fread(&(BitmapHeader->YPelsPerMeter), sizeof(BitmapHeader->YPelsPerMeter), 1, BinaryIFile);
    	fread(&(BitmapHeader->ClrUsed), sizeof(BitmapHeader->ClrUsed), 1, BinaryIFile);
    	fread(&(BitmapHeader->ClrImportant), sizeof(BitmapHeader->ClrImportant), 1, BinaryIFile);
    }
    Which I believe is working correctly now, and I will move to implementing it in my Terrain Program and hopefully get some nice Terrain's in there.

    I would guess that my 24-Bit BMP is the reason for not having an Alpha Channel? 8 Red, 8 Green, 8 Blue?
    Last edited by Epo; 09-23-2005 at 09:03 PM.
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-23-2008, 03:32 AM
  2. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 06:33 PM
  3. CreateDevice failing
    By MadCow257 in forum Game Programming
    Replies: 6
    Last Post: 03-14-2006, 09:03 PM
  4. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM
  5. DX9 and Dev-C++
    By Ashes999 in forum Windows Programming
    Replies: 5
    Last Post: 06-10-2003, 12:19 AM