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).]