Newbie needs help (bitmap code not working!)
Well, get this weird errors:
--------------------Configuration: OpenGL Basecode - Win32 Debug--------------------
Compiling...
Main.cpp
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(22) : error C2065: ''FILE'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(22) : error C2065: ''filePtr'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(22) : warning C4552: ''*'' : operator has no effect; expected operator with side-effect
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(29) : error C2065: ''fopen'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(34) : error C2065: ''fread'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(37) : error C2065: ''BITMAP_ID'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(39) : error C2065: ''fclose'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(47) : error C2065: ''fseek'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(47) : error C2065: ''SEEK_SET'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(50) : error C2065: ''malloc'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(55) : error C2065: ''free'' : undeclared identifier
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(71) : warning C4018: ''<'' : signed/unsigned mismatch
C:\Mina dokument\Programmering\OpenGL Basecode\Main.cpp(284) : error C2065: ''bitmapImage'' : undeclared identifier
Error executing cl.exe.
OpenGL Basecode.exe - 11 error(s), 2 warning(s)
When I am trying to run this code:
// DEFINES ////////////////////////////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
// INCLUDES ///////////////////////////////////////////////////////////////////
#include
#include
#include
#include
// GLOBALS ////////////////////////////////////////////////////////////////////
HDC g_HDC; //Header of global device context
float angle = 0.0f; //Angle variable used fro rotation
// GLOBALS FOR TEXTURES ///////////////////////////////////////////////////////
BITMAPINFOHEADER bitmapInfoHeader; //The bitmap info header
unsigned char* bitmapData; //The bitmap info data
// FUNCTION USED TO LOAD BITMAP FILES /////////////////////////////////////////
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
//Varialbes
FILE *filePtr; //The file pointer
BITMAPFILEHEADER bitmapFileHeader; //Bitmap file header
unsigned char *bitmapImage; //Bitmap image data
int imageIdx = 0; //Image index counter
unsigned char tempRGB; //Swap varaible
//Open filename in "read binary" mode:
filePtr = fopen(filename, "rb");
if (filePtr == NULL)
return NULL;
//Read bitmap file header:
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
//Verify that the loaded file is a bitmap by lookin for the universal bitmap id
if (bitmapFileHeader.bfType != BITMAP_ID)
{
fclose(filePtr);
return NULL;
}
//Read the bitmap inforamtion header:
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
//Move the file pointer to the beginning of the bitmap data:
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
//Allocate enough memory for the bitmap image data
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
//Verify memory allocation
if (!bitmapImage)
{
free(bitmapImage);
fclose(filePtr);
return NULL;
}
//Read in the bitmap image data
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
//Make sure bitmap image data was read:
if (bitmapImage == NULL)
{
fclose(filePtr);
return NULL;
}
//Swap the R and B values to get RGB since the bitmap color format is in BGR
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;
}
//Close tha file and return tha bitmap image data!
fclose(filePtr);
return bitmapImage;
}
// FUNCTION TO SET UP THE PIXELFORMAT FOR THE DEVICE CONTEXT //////////////////
void SetupPixelFormat(HDC hDC)
{
int nPixelFormat; //The Pixel format index
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0 };
//Choose best matching pixel format, return index
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
//Set pixel format to device context, yo!
SetPixelFormat(hDC, nPixelFormat, &pfd);
}
// THE WINDOWS PROCEDURE MESSAGE HANDLER //////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//Variables
static HGLRC hRC;
static HDC hDC;
int width, height;
//Message handler
switch(message)
{
case WM_CREATE:
hDC = GetDC(hwnd);
g_HDC = hDC;
SetupPixelFormat(hDC);
//Create rendering context and make it current:
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
//Enable blending:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return 0;
break;
case WM_CLOSE:
//Deselect rendering context and delete it:
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam); //retrive height and width
width = LOWORD(lParam);
if (height==0) //make divide by zero imposible
{
height=1;
}
//reset tha viewport to new dimensions:
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//calculate aspect ratio of window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return 0;
break;
default:
break;
}
return (DefWindowProc(hwnd, message, wParam, lParam));
}
// THE PROGRAM ENTRY POINT, WINMAIN() /////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
//Varaibles
WNDCLASSEX windowClass; // window class
HWND hwnd; // window handle
MSG msg; // message
bool done; // flag saying when the app is finished
//Fill out the windows structure:
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "MyClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
//Register the windows class:
if (!RegisterClassEx(&windowClass))
return 0;
//Class registred, so now lets create tha window!
hwnd = CreateWindowEx(NULL,
"MyClass",
"OpenGL Basecode",
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU,
100, 100,
400, 400,
NULL,
NULL,
hInstance,
NULL);
//Check if window creation failed (in other words, does hwnd equal NULL?)
if (!hwnd)
return 0;
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
done = false; //Init tha loop condition varaible!
//Main message loop! (loops over and over until your program quits)
while (!done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if (msg.message == WM_QUIT) //Is there a quit message in tha que?
{
done = true; //If so, quit!
}
else
{
// Do rendering here...
// Clear screen and depth buffer, and reset camera pos
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef( 0.0f , 0.0f, -10.0f ); //Move ten units back into tha screen
glBegin(GL_QUADS); //And draw a huge gray quad
glColor4f(0.3f,0.3f,0.3f, 1.0f);
glVertex3f( -10.0f, 10.0f, 0.0f);
glVertex3f( 10.0f, 10.0f, 0.0f);
glVertex3f( 10.0f, -10.0f, 0.0f);
glVertex3f( -10.0f, -10.0f, 0.0f);
glEnd();
//Reset camera pos
glLoadIdentity();
//Handle rotation
angle += 0.65f;
if (angle >= 360.0f)
angle = 0.0f;
glTranslatef( 0.0f , 0.0f, -5.0f ); //Move back five units in to the screen...
glRotatef(angle, 1.0f,0.0f,0.0f); //...setup rotation...
glRotatef(angle, 0.0f,1.0f,0.0f); //...setup rotation...
glBegin(GL_TRIANGLES); //...and draw a nice triangle
glColor4f(1.0f,0.0f,0.0f, 0.6f);
glVertex3f( -1.0f, -1.0f, 0.0f);
glColor4f(0.0f,1.0f,0.0f, 0.6f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor4f(0.0f,0.0f,1.0f, 0.6f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
bitmapData = LoadBitmapFile("test.bmp", &bitmapInfoHeader);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glRasterPos2i(100, 100);
glDrawPixels(bitmapInfoHeader.biWidth, bitmapInfoHeader.biHeight,GL_RGB,
GL_UNSIGNED_BYTE, bitmapImage);
SwapBuffers(g_HDC);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
Can anyone help me with this?
Thanks in beforehand...
-=Moogle=-
Dude, your missing your include files, thats why your getting all this "Undeclared identifier" errors,
eg.
#include
all you have is the #include, and no file.
eg.
#include
all you have is the #include, and no file.
my email is xaknafein@hotmail.com
no, include files jsut dont appear when you post.
------------------------------Put THAT in your smoke and pipe it
Try writing the load bitmap functions again. Thats where all of your erros seem to be.
And put this up top with the lean and mean define:
#define BITMAP_ID 0x4D42
"I've sparred with creatures from the nine hells themselves... I barely plan on breaking a sweat here, today."~Drizzt Do'Urden
Edited by - Drizzt DoUrden on September 23, 2001 5:21:06 PM
And put this up top with the lean and mean define:
#define BITMAP_ID 0x4D42
"I've sparred with creatures from the nine hells themselves... I barely plan on breaking a sweat here, today."~Drizzt Do'Urden
Edited by - Drizzt DoUrden on September 23, 2001 5:21:06 PM
------------------------------Put THAT in your smoke and pipe it
It seems like i have to include some file i dont include...
I have currently included:
windows.h
gl/gl.h
gl/glu.h
gl/glaux.h
I have currently included:
windows.h
gl/gl.h
gl/glu.h
gl/glaux.h
-=Moogle=-
#include stdio.h
#include stdlib.h
Try including them.. they are in my OpenGL setups, I dont know if they will help..
#include stdlib.h
Try including them.. they are in my OpenGL setups, I dont know if they will help..
------------------------------Put THAT in your smoke and pipe it
stdio.h is the file you want....since it includes the FILE stuff your compiler is missing..... It''s just a easy as that...
(You probably found that out already though...)
Take Care!
- -- ---[XaOs]--- -- -
[ project fy ]
(You probably found that out already though...)

Take Care!
- -- ---[XaOs]--- -- -
[ project fy ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement