PDA

View Full Version : glLoadTGeA(() does not take 5 parameters...error c2660



reader1
05-20-2015, 09:24 AM
This is from SuperBible, I count it really has 5 paramters, but why occur such error?

// LoadTGA.c
// Loads a Targa file for OpenGL // Richard S. Wright Jr.
// OpenGL SuperBible
// This really only works with 24/32/8 bit targas

//#include "GLTools.h"
#include <stdio.h>

// Define targa header.
#pragma pack(1)
typedef struct
{
GLbyte identsize; // Size of ID field that follows header (0)
GLbyte colorMapType; // 0 = None, 1 = paletted
GLbyte imageType; // 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle
unsigned short colorMapStart; // First colour map entry
unsigned short colorMapLength; // Number of colors
unsigned char colorMapBits; // bits per palette entry
unsigned short xstart; // image x origin
unsigned short ystart; // image y origin
unsigned short width; // width in pixels
unsigned short height; // height in pixels
GLbyte bits; // bits per pixel (8 16, 24, 32)
GLbyte descriptor; // image descriptor
} TGAHEADER;
#pragma pack(8)

////////////////////////////////////////////////////////////////////
// only, no palettes, no RLE encoding.
GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint *iHeight, GLint *iComponents, GLenum *eFormat)
{
FILE *pFile; // File pointer
TGAHEADER tgaHeader; // TGA file header
unsigned long lImageSize; // Size in bytes of image
short sDepth; // Pixel depth;
GLbyte *pBits = NULL; // Pointer to bits

// Default/Failed values
*iWidth = 0;
*iHeight = 0;
*eFormat = GL_BGR_EXT;
*iComponents = GL_RGB8;

// Attempt to open the fil
fopen_s(&pFile,szFileName, "rb");
if(pFile == NULL)
return NULL;

// Read in header (binary)
fread(&tgaHeader, 18, 1, pFile); //18/* sizeof(TGAHEADER)*/

// Get width, height, and depth of texture
*iWidth = tgaHeader.width;
*iHeight = tgaHeader.height;
sDepth = tgaHeader.bits / 8;

// Put some validity checks here. Very simply, I only understand
// or care about 8, 24, or 32 bit targa's.
if(tgaHeader.bits != 8 && tgaHeader.bits != 24 && tgaHeader.bits != 32)
return NULL;

// Calculate size of image buffer
lImageSize = tgaHeader.width * tgaHeader.height * sDepth;

// Allocate memory and check for success
pBits = malloc(lImageSize * sizeof(GLbyte));
if(pBits == NULL)
return NULL;

if(fread(pBits, lImageSize, 1, pFile) != 1)
{
free(pBits);
return NULL;
}

// Set OpenGL format expected
switch(sDepth)
{
case 3: // Most likely case
*eFormat = GL_BGR_EXT;
*iComponents = GL_RGB8;
break;
case 4:
*eFormat = GL_BGRA_EXT;
*iComponents = GL_RGBA8;
break;
case 1:
*eFormat = GL_LUMINANCE;
*iComponents = GL_LUMINANCE8;
break;
};


// Done with File
fclose(pFile);

// Return pointer to image data
return pBits;
}



#include "stdafx.h"

//#include "GLee.h"

#include <gltools.h>
#include "GL/glut.h" //
#include <math3d.h>
#include "loadpic.h"

#pragma comment(lib, "glew32.lib")

static GLint iWidth=0, iHeight=0, iComponents;
static GLenum eFormat;
static GLfloat xRot, yRot;

void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
..........
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
GLbyte *pImage = NULL;

pImage = gltLoadTGA("..\\stone.tga", &iWidth, &iHeight, &iComponents, &eFormat);

if (pImage).........

reader1
05-21-2015, 07:25 AM
As if there is no one who has met such touble. search on the web sites, it seems something wrong with setting..property-lib-attachment? or....