I see quite a lot of problems with your code... Keep in mind that I haven't coded in C in some years:
- AFAIK there is no Visual Studio that features a C99 compiler, therefore // comments can't be in C code, use /* */ comments;
- your TARGA typedef isn't doing what you expect;
- the format member of the TARGA struct can't hold values like GL_RGB (they will overflow): you want GLint, IIRC;
- the signatures of TgaDraw() in the header and the implementation files don't match (one takes an unsigned, another a int);
- in TgaInit(), FilePointer should be a FILE*, but it's a FILE;
- in TgaInit(), you dereference "path" where you shouldn't;
- in TgaInit(), since FilePointer must be a FILE*, you don't want to take its address anymore in fread();
- in TgaInit(), you often derefence members of the tga pointer, apparently thinking that you are dereferencing the pointer itself. Instead of doing, say, *tga.error, use tga->error;
- in TgaInit(), you try to reference the Width member of the TARGA struct (uppercase 'W') but it has a width member (lowercase 'w');
- you dereference CM_Data to store the pointer returned by malloc, which is wrong;
- you attempt to fread into a variable called "Data", which doesn't exist. On the same line, you try to take that variable's size. I don't know if that's supposed to be the TARGA structure's Data member, or the variable CM_Data;
- in TgaInit(), you attempt to strcpy into a variable called "Error", which you dereference. I see no such variable declared anywhere. I assume it's the TARGA structure's Error, in which case you'll want to use tga->Error as above;
- TgaInit() sometimes returns TRUE or FALSE, but I don't see them typedef'ed anywhere. I could be wrong (probably am), but I don't think that any standard C header defines these, so you should probably check for them with ifndef and define them if they aren't defined;
- TgaDraw(), you have a ';' after "i++" in the for-loop.
That's all I could find from a purely syntaxic point of vue. I'm not saying the resulting code is correct, but with all the above fixes and by removing all the Windows-specific headers, I could build an object file.
The code I ended up with follows. Keep in mind that it's been modified to build. That is, I had to comment at least one line of your code (the one that references the inexistant "Data" variable), I removed some headers because I don't use Windows (I should have commented them, sorry) and added an include (SDL_opengl.h). It definitely doesn't mean that it behaves correctly.
If I may, I'd like to suggest that you pick a naming convention and stick to it. Also please avoid strcpy and family if at all possible (prefer the strncpy, or use the compiler-specific ones if portability isn't an issue). Finally, I'm afraid to say that you'll probably have to review pointers, as you seem a little confused by them. Manipulating pointers without understanding them is going to lead to terrible headaches at the very best. This is friendly advice and in no way meant to put you down.
/* targa.h */#ifndef IF260C3E0C600EA28A36E4E2FA546302B_627186979177454405#define IF260C3E0C600EA28A36E4E2FA546302B_627186979177454405#include <time.h>#include <stdio.h>#include <stdlib.h>#include "SDL.h"#include "SDL_opengl.h"/*#include "Lobster.h"*/#define ERROR_LIMIT 64#define TRUE 1#define FALSE 0 typedef struct { unsigned int xRes, YRes; char Error[ERROR_LIMIT]; char* Data; char error[ERROR_LIMIT]; short xOrigin; short yOrigin; short width; short height; short bpp; char ImgOrigin; char AlphaBits; GLint format;} TARGA;/*Accepts a TARGA struct, and loads the data at path into it*/int TgaInit(const char *path, TARGA *tga);/*Draws an array of Targas*/int TgaDraw(TARGA *tga, int *xCoord, int *yCoord, /*unsigned*/ int number);#endif /* IF260C3E0C600EA28A36E4E2FA546302B_627186979177454405 */
/* targa.cpp */#include "targa.h"/********************************** * * TgaInit * Loads a targa from path into tga * **********************************/int TgaInit(const char *path, TARGA *tga) { /*Various stuff useful for loading a targa and not much else*/ short CM_Start; short CM_Length; char CM_EntSize; char idLength; char ImgDescriptor; char CM_Type; char ImgType; FILE *FilePointer; char *CM_Data; FilePointer = fopen(path, "r"); fread(&idLength, sizeof(idLength), 1, FilePointer); fread(&CM_Type, sizeof(CM_Type), 1, FilePointer); fread(&ImgType, sizeof(ImgType), 1, FilePointer); if (ImgType < 1 || ImgType > 11) { strcpy(tga->error, "Image is not a legal Targa"); return FALSE; } fread(&CM_Start, sizeof(CM_Start), 1, FilePointer); fread(&CM_Length, sizeof(CM_Length), 1, FilePointer); fread(&CM_EntSize, sizeof(CM_EntSize), 1, FilePointer); fread(&tga->xOrigin, sizeof(tga->xOrigin), 1, FilePointer); fread(&tga->yOrigin, sizeof(tga->yOrigin), 1, FilePointer); fread(&tga->width, sizeof(tga->width), 1, FilePointer); fread(&tga->height, sizeof(tga->height), 1, FilePointer); fread(&tga->bpp, sizeof(tga->bpp), 1, FilePointer); fread(&ImgDescriptor, sizeof(ImgDescriptor), 1, FilePointer); tga->AlphaBits = ImgDescriptor & 0x0D; tga->ImgOrigin = ImgDescriptor & 0x30; if (tga->AlphaBits == 0) tga->format = GL_RGB; else tga->format = GL_RGBA; fseek(FilePointer, idLength, SEEK_CUR); tga->Data = malloc(tga->width * tga->height * sizeof(tga->Data)); /*TODO: Add in an if statement to check for a CM before doing this*/ /*char*/ CM_Data = malloc(CM_Length * CM_EntSize); /*TODO: Work on adding support for more than just 8 bits per channel*/ fread(&CM_Data, sizeof(CM_Data), 1, FilePointer); /*fread(&Data, sizeof(*Data), 1, FilePointer);*/ if (CM_Type != 0) { /*cm_to_true(*CM_Data);*/ /*TODO: Add color map support*/ strcpy(tga->Error, "Color maps not supported"); return FALSE; } return TRUE;}/**************************************** * *TgaDraw *Accepts an array of targas and draws them * ******************************************/int TgaDraw(TARGA *tga, int *xCoord, int *yCoord, int number) { unsigned int i; for (i = 0; i <= number; i++) { glRasterPos2i(xCoord, yCoord); glDrawPixels(tga.width, tga.height, tga.format, GL_UNSIGNED_BYTE, tga.Data); } return TRUE;}
Hope this helps.