PDA

View Full Version : help me out with these errors.



prashantgp
12-08-2002, 09:40 PM
hi all,
below is my code.

#include<stdlib.h>
#include<stdio.h>
#include"GL/glut.h"

/*
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>*/
#include <math.h>


// Keep track of effects step
int nStep = 0;

GLuint textures[4];


///////////////////////////////////////////////////////////////////////////////
// This function opens the bitmap file given (szFileName), verifies that it is
// a 24bit .BMP file and loads the bitmap bits needed so that it can be used
// as a texture. The width and height of the bitmap are returned in nWidth and
// nHeight. The memory block allocated and returned must be deleted with delete [];
// The returned array is an 888 BGR texture (use GL_BGR_EXT or BGRtoRGB for
// glTextImage2D
BYTE* gltReadBMPBits(const char *szFileName, int *nWidth, int *nHeight)
{
HANDLE hFileHandle;
BITMAPINFO *pBitmapInfo = NULL;
unsigned long lInfoSize = 0;
unsigned long lBitSize = 0;
BYTE *pBits = NULL; // Bitmaps bits
BITMAPFILEHEADER bitmapHeader;
DWORD dwBytes;

// Open the Bitmap file
hFileHandle = CreateFile(szFileName,GENERIC_READ,FILE_SHARE_READ ,
NULL,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL) ;

// Check for open failure (most likely file does not exist).
if(hFileHandle == INVALID_HANDLE_VALUE)
return NULL;

// File is Open. Read in bitmap header information
ReadFile(hFileHandle,&bitmapHeader,sizeof(BITMAPFILEHEADER),
&dwBytes,NULL);

// Check for a couple of simple errors
if(dwBytes != sizeof(BITMAPFILEHEADER))
return FALSE;

// Check format of bitmap file
if(bitmapHeader.bfType != 'MB')
return FALSE;

// Read in bitmap information structure
lInfoSize = bitmapHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
pBitmapInfo = (BITMAPINFO *) malloc(sizeof(BYTE)*lInfoSize);
ReadFile(hFileHandle,pBitmapInfo,lInfoSize,&dwBytes,NULL);

if(dwBytes != lInfoSize)
{
free(pBitmapInfo);
CloseHandle(hFileHandle);
return FALSE;
}

// Save the size and dimensions of the bitmap
*nWidth = pBitmapInfo->bmiHeader.biWidth;
*nHeight = pBitmapInfo->bmiHeader.biHeight;
lBitSize = pBitmapInfo->bmiHeader.biSizeImage;

// If the size isn't specified, calculate it anyway
if(pBitmapInfo->bmiHeader.biBitCount != 24)
{
free(pBitmapInfo);
return FALSE;
}

if(lBitSize == 0)
lBitSize = (*nWidth *
pBitmapInfo->bmiHeader.biBitCount + 7) / 8 *
abs(*nHeight);

// Allocate space for the actual bitmap
free(pBitmapInfo);
pBits = malloc(sizeof(BYTE)*lBitSize);

// Read in the bitmap bits, check for corruption
if(!ReadFile(hFileHandle,pBits,lBitSize,&dwBytes,NULL) | |
dwBytes != (sizeof(BYTE)*lBitSize))
pBits = NULL;

// Close the bitmap file now that we have all the data we need
CloseHandle(hFileHandle);

return pBits;
}

// Called to draw scene
void RenderScene(void)
{
GLfloat cubeXform[4][4];

// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);

glPushMatrix();

// Draw plane that the cube rests on
glDisable(GL_LIGHTING);
if(nStep == 5)
{
glColor3ub(255,255,255);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-100.0f, -25.3f, -100.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-100.0f, -25.3f, 100.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(100.0f, -25.3f, 100.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(100.0f, -25.3f, -100.0f);
glEnd();
}
glPopMatrix();

}


void SetupRC()
{
BYTE *pBytes;
int nWidth, nHeight;

// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);

// Load the texture objects
pBytes = gltReadBMPBits("floor.bmp", &nWidth, &nHeight);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,nWidth, nHeight, 0,
GL_BGR_EXT, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);
}


void KeyPressFunc(unsigned char key, int x, int y)
{
if(key == 97)
nStep = 5;
if(key == 27)
{ exit(0);
break;}
// Refresh the Window
glutPostRedisplay();
}


void ChangeSize(int w, int h)
{
// Calculate new clipping volume
GLfloat windowWidth;
GLfloat windowHeight;

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;

// Keep the square square
if (w <= h)
{
windowHeight = 100.0f*h/w;
windowWidth = 100.0f;
}
else
{
windowWidth = 100.0f*w/h;
windowHeight = 100.0f;
}


// Reset the coordinate system before modifying
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Set the viewport to be the entire window
glViewport(0, 0, w, h);

// Set the clipping volume
glOrtho(-100.0f, windowWidth, -100.0f, windowHeight, -200.0f, 200.0f);

glLightfv(GL_LIGHT0,GL_POSITION, lightpos);

glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
glRotatef(330.0f, 0.0f, 1.0f, 0.0f);
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("3D Effects Demo");
glutReshapeFunc(ChangeSize);
glutKeyboardFunc(KeyPressFunc);
glutDisplayFunc(RenderScene);
glGenTextures(1,textures);

SetupRC();

glutMainLoop();
glDeleteTextures(1,textures);
return 0;
}

when i am compile it i am getting the following errors. help me out with them.


[user1@mazda user1]$ gcc -o a texture.c -lm -lGL -lGLU -lglut
texture.c:26: parse error before `*'
texture.c: In function `gltReadBMPBits':
texture.c:28: `HANDLE' undeclared (first use in this function)
texture.c:28: (Each undeclared identifier is reported only once
texture.c:28: for each function it appears in.)
texture.c:28: parse error before `hFileHandle'
texture.c:29: `BITMAPINFO' undeclared (first use in this function)
texture.c:29: `pBitmapInfo' undeclared (first use in this function)
texture.c:29: invalid lvalue in assignment
texture.c:30: parse error before `unsigned'
texture.c:32: `BYTE' undeclared (first use in this function)
texture.c:32: `pBits' undeclared (first use in this function)
texture.c:32: invalid lvalue in assignment
texture.c:33: `BITMAPFILEHEADER' undeclared (first use in this function)
texture.c:33: parse error before `bitmapHeader'
texture.c:34: `DWORD' undeclared (first use in this function)
[user1@mazda user1]$ gcc -o a texture.c -lm -lGL -lGLU -lglut
texture.c:26: parse error before `*'
texture.c: In function `gltReadBMPBits':
texture.c:28: `HANDLE' undeclared (first use in this function)
texture.c:28: (Each undeclared identifier is reported only once
texture.c:28: for each function it appears in.)
texture.c:28: parse error before `hFileHandle'
texture.c:29: `BITMAPINFO' undeclared (first use in this function)
texture.c:29: `pBitmapInfo' undeclared (first use in this function)
texture.c:29: invalid lvalue in assignment
texture.c:30: parse error before `unsigned'
texture.c:32: `BYTE' undeclared (first use in this function)
texture.c:32: `pBits' undeclared (first use in this function)
texture.c:32: invalid lvalue in assignment
texture.c:33: `BITMAPFILEHEADER' undeclared (first use in this function)
texture.c:33: parse error before `bitmapHeader'
texture.c:34: `DWORD' undeclared (first use in this function)

thanks in advance.


[This message has been edited by prashantgp (edited 12-09-2002).]

SThomas
12-09-2002, 02:42 AM
BYTE, DWORD, BITMAPINFO, HANDLE, etc are all windows specific data types. you get access to them by #including windows.h, which you currently have commented out.



/*
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>*/

since it looks like you're using unix or linux, windows.h isn't even available on your system (at least i can't imagine why it would be). you need to rewrite the code to not use those data types. that shouldn't be too difficult though. a BYTE is just an unsigned char, a DWORD is a 32 bit integer (or maybe unsigned integer), a HANDLE is some kind of generic pointer value (or maybe just a regular old int). you'll probably want to move away from using windows bitmaps on unix/linux though. check out targas (.tga) instead.

prashantgp
12-09-2002, 11:34 PM
hi ,
i typedefined the WORD,DWORD etc.
now those errors are removed and i am getting the following errors.
pls help me out.

[user1@mazda user1]$ gcc -o a nt.c -lm -lGL -lGLU -lglut
nt.c: In function `gltReadBMPBits':
nt.c:99: `GENERIC_READ' undeclared (first use in this fun
nt.c:99: (Each undeclared identifier is reported only onc
nt.c:99: for each function it appears in.)
nt.c:99: `FILE_SHARE_READ' undeclared (first use in this
nt.c:100: `OPEN_EXISTING' undeclared (first use in this f
nt.c:100: `FILE_FLAG_SEQUENTIAL_SCAN' undeclared (first u
nt.c:103: `INVALID_HANDLE_VALUE' undeclared (first use in
nt.c:112: `FALSE' undeclared (first use in this function)
nt.c:115: warning: multi-character character constant
[user1@mazda user1]$

bye

Bob
12-10-2002, 01:29 AM
You're using file I/O functions that are available on Windows only (through windows.h). Use some standard file I/O instead.

[This message has been edited by Bob (edited 12-10-2002).]