本文整理汇总了C++中LOG::OutputSuccess方法的典型用法代码示例。如果您正苦于以下问题:C++ LOG::OutputSuccess方法的具体用法?C++ LOG::OutputSuccess怎么用?C++ LOG::OutputSuccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LOG
的用法示例。
在下文中一共展示了LOG::OutputSuccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Shutdown
void WINDOW::Shutdown(void) //PROPERLY KILL WINDOW
{
//Delete font display lists
glDeleteLists(base, 96);
if (fullscreen)
{
ChangeDisplaySettings(NULL, 0); //restore desktop mode
ShowCursor(TRUE); //show mouse cursor
}
errorLog.OutputNewline();
if(hRC) //have a rendering context?
{
if(!wglMakeCurrent(NULL, NULL)) //try to release rend cont
{
errorLog.OutputError("Release of DC and RC Failed.");
}
else
errorLog.OutputSuccess("DC and RC released.");
if(!wglDeleteContext(hRC)) //try to delete RC
{
errorLog.OutputError("Release Rendering Context Failed.");
}
else
errorLog.OutputSuccess("Rendering Context Released.");
hRC=NULL; //set RC to NULL
}
if(hDC && !ReleaseDC(hWnd, hDC)) //Are we able to release DC?
{
errorLog.OutputError("Release of Device Context Failed.");
hDC=NULL;
}
else
errorLog.OutputSuccess("Device Context Released.");
if(hWnd && !DestroyWindow(hWnd)) //Can we destroy window?
{
errorLog.OutputError("Could not release hWnd");
hWnd=NULL;
}
else
errorLog.OutputSuccess("hWnd released.");
if (!UnregisterClass("OpenGL", hInstance)) //can we unreg. class?
{
errorLog.OutputError("Could Not Unregister Class.");
hInstance=NULL;
}
else
errorLog.OutputSuccess("Class unregistered.");
}
示例2: WinMain
//ENTRY POINT FOR APPLICATION
//CALL WINDOW CREATION ROUTINE, DEAL WITH MESSAGES, WATCH FOR INTERACTION
int WINAPI WinMain( HINSTANCE hInstance, //instance
HINSTANCE hPrevInstance, //Previous Instance
LPSTR lpCmdLine, //command line parameters
int nCmdShow) //Window show state
{
//Initiation
errorLog.Init("Error Log.txt");
//init variables etc, then GL
if(!DemoInit())
{
errorLog.OutputError("Demo Initiation failed");
return 0;
}
else
errorLog.OutputSuccess("Demo Initiation Successful");
if(!GLInit())
{
errorLog.OutputError("OpenGL Initiation failed");
return 0;
}
else
errorLog.OutputSuccess("OpenGL Initiation Successful");
//Main Loop
for(;;)
{
if(!(window.HandleMessages())) break;//handle windows messages, quit if returns false
UpdateFrame();
RenderFrame();
}
DemoShutdown();
errorLog.OutputSuccess("Exiting...");
return (window.msg.wParam); //Exit The Program
}
示例3: LoadNV_vertex_program
bool LoadNV_vertex_program(char * filename, GLuint programID)
{
//load from file
std::ifstream vpFile(filename, std::ios::in | std::ios::binary);
if(vpFile.fail())
{
printf("Unable to open vertex program\n");
return false;
}
//calculate the size of the file
vpFile.seekg(0, std::ios::end);
int vpSize=vpFile.tellg();
vpFile.seekg(0, std::ios::beg);
//allocate memory
unsigned char * vpText=new unsigned char[vpSize];
if(!vpText)
{
printf("Unable to allocate space for vertex program text\n");
return false;
}
//read file
vpFile.read(reinterpret_cast<char *>(vpText), vpSize);
vpFile.close();
//load program
glLoadProgramNV(GL_VERTEX_PROGRAM_NV, programID, vpSize, vpText);
if(vpText)
delete [] vpText;
vpText=NULL;
//Output if there was an error
int errorPos;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errorPos);
if(errorPos!=-1)
{
errorLog.OutputError("Program error at position %d in %s\n", errorPos, filename);
return false;
}
else
errorLog.OutputSuccess("%s loaded correctly", filename);
return true;
}
示例4: SetUpEXT_texture_edge_clamp
bool SetUpEXT_texture_edge_clamp()
{
//Check for support
char * extensionString=(char *)glGetString(GL_EXTENSIONS);
char * extensionName="GL_EXT_texture_edge_clamp";
char * endOfString; //store pointer to end of string
unsigned int distanceToSpace; //distance to next space
endOfString=extensionString+strlen(extensionString);
//loop through string
while(extensionString<endOfString)
{
//find distance to next space
distanceToSpace=strcspn(extensionString, " ");
//see if we have found extensionName
if((strlen(extensionName)==distanceToSpace) &&
(strncmp(extensionName, extensionString, distanceToSpace)==0))
{
EXT_texture_edge_clamp_supported=true;
}
//if not, move on
extensionString+=distanceToSpace+1;
}
if(!EXT_texture_edge_clamp_supported)
{
errorLog.OutputError("EXT_texture_edge_clamp unsupported!");
return false;
}
errorLog.OutputSuccess("EXT_texture_edge_clamp supported!");
//get function pointers
//none specified
return true;
}
示例5: DemoInit
//Set up variables
bool DemoInit()
{
if(!window.Init("Project Template", 640, 480, 32, 24, 8, WINDOWED_SCREEN))
return 0; //quit if not created
SetUpARB_multitexture();
SetUpARB_texture_cube_map();
SetUpEXT_texture_edge_clamp();
SetUpNV_register_combiners();
SetUpNV_register_combiners2();
SetUpNV_vertex_program();
//Check for necessary extensions
if( !ARB_multitexture_supported || !ARB_texture_cube_map_supported ||
!EXT_texture_edge_clamp_supported || !NV_register_combiners_supported ||
!NV_vertex_program_supported)
return false;
//Check for single-pass chromatic aberration states
GLint maxTextureUnits;
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits);
if( NV_register_combiners2_supported && maxTextureUnits>=4)
{
errorLog.OutputSuccess("Single Pass Chromatic Aberration Supported!");
pathOneSupported=true;
renderPath=CHROMATIC_SINGLE;
}
camera.Init(VECTOR3D(0.0f, 0.0f, 4.0f), 2.5f, 10.0f);
if( !cubeMapPosX.Load("cube_face_posx.tga") ||
!cubeMapNegX.Load("cube_face_negx.tga") ||
!cubeMapPosY.Load("cube_face_posy.tga") ||
!cubeMapNegY.Load("cube_face_negy.tga") ||
!cubeMapPosZ.Load("cube_face_posz.tga") ||
!cubeMapNegZ.Load("cube_face_negz.tga"))
return false;
//Build a texture from the data
glGenTextures(1, &cubeMapTexture); //Generate Texture ID
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture); //Bind texture
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
0, GL_RGBA8, cubeMapPosX.width, cubeMapPosX.height, 0,
cubeMapPosX.format, GL_UNSIGNED_BYTE, cubeMapPosX.data);
glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
0, GL_RGBA8, cubeMapNegX.width, cubeMapNegX.height, 0,
cubeMapNegX.format, GL_UNSIGNED_BYTE, cubeMapNegX.data);
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
0, GL_RGBA8, cubeMapPosY.width, cubeMapPosY.height, 0,
cubeMapPosY.format, GL_UNSIGNED_BYTE, cubeMapPosY.data);
glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
0, GL_RGBA8, cubeMapNegY.width, cubeMapNegY.height, 0,
cubeMapNegY.format, GL_UNSIGNED_BYTE, cubeMapNegY.data);
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
0, GL_RGBA8, cubeMapPosZ.width, cubeMapPosZ.height, 0,
cubeMapPosZ.format, GL_UNSIGNED_BYTE, cubeMapPosZ.data);
glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
0, GL_RGBA8, cubeMapNegZ.width, cubeMapNegZ.height, 0,
cubeMapNegZ.format, GL_UNSIGNED_BYTE, cubeMapNegZ.data);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
//reset timer for start
timer.Reset();
return true;
}
示例6: sizeof
//Load8BitBMP - load an 8 bit paletted bitmap file
bool IMAGE::Load8BitBMP(char * filename)
{
errorLog.OutputSuccess("Loading %s in Load8bitBMP()", filename);
//set bpp and format
bpp=24; //after conversion
format=GL_RGB;
FILE * file; //the texture file
BITMAPFILEHEADER fileHeader; //bitmap file header
BITMAPINFOHEADER infoHeader; //bitmap info header
//open file for reading
file=fopen(filename, "rb");
if(file==NULL)
{
errorLog.OutputError("Unable to open %s", filename);
return false;
}
//read the file header
fread(&fileHeader, sizeof(BITMAPFILEHEADER), 1, file);
//check it's a bitmap
if(fileHeader.bfType != BITMAP_ID)
{
fclose(file);
errorLog.OutputError("%s is not a legal .BMP", filename);
return false;
}
//read in the information header
fread(&infoHeader, sizeof(BITMAPINFOHEADER), 1, file);
//set size
width=infoHeader.biWidth;
height=infoHeader.biHeight;
//make space for palette
unsigned char * palette=new unsigned char[256*4];
if(!palette)
{
errorLog.OutputError("Unable to alllocate memory for palette");
return false;
}
//load the palette
fread(palette, 256*4, 1, file);
//point file to the beginning of the data
fseek(file, fileHeader.bfOffBits, SEEK_SET);
//calculate the stride in bytes between one row and the next
unsigned int stride=width;
if(width%4 != 0)
stride+=4-width%4;
//allocate space for color indices
unsigned char * indices=new unsigned char[stride*height];
if(!indices)
{
errorLog.OutputError("Unable to allocate memory for indices");
return false;
}
//load indices
fread(indices, 1, stride*height, file);
//close the file
fclose(file);
//allocate space for the image data
data=new unsigned char[stride*height*bpp/8];
if(!data)
{
fclose(file);
errorLog.OutputError("Unable to allocate memory for %s", filename);
return false;
}
//calculate the color values - keeping the padding colors
for(unsigned int currentRow=0; currentRow<height; currentRow++)
{
for(unsigned int i=0; i<stride; i++)
{
data[(currentRow*stride+i)*3+0]=palette[indices[currentRow*stride+i]*4+2];
data[(currentRow*stride+i)*3+1]=palette[indices[currentRow*stride+i]*4+1];
data[(currentRow*stride+i)*3+2]=palette[indices[currentRow*stride+i]*4+0];//BGR
}
}
errorLog.OutputSuccess("Loaded %s correctly.", filename);
return true;
}
示例7: LoadAlphaTGA
//load in an 8 bit greyscale TGA as an alpha channel
bool IMAGE::LoadAlphaTGA(char * filename)
{
unsigned char TGAHeader[12]={0, 1, 1, 0, 0, 0, 1, 24, 0, 0, 0, 0};
unsigned char TGAcompare[12]; //Used to compare TGA header
unsigned char header[6]; //First 6 useful bytes of the header
errorLog.OutputSuccess("Loading %s in LoadAlphaTGA()", filename);
if(!(format==GL_RGB || format==GL_RGBA))
{
errorLog.OutputError("Can only load an alpha channel to RGB / RGBA format images. %s caused error", filename);
return false;
}
FILE * file = fopen(filename, "rb"); //Open the TGA file
if(file == NULL) //Does the file exist?
{
errorLog.OutputError("%s does not exist.", filename);
return false;
}
if( fread(TGAcompare, 1, sizeof(TGAcompare), file)!=sizeof(TGAcompare)|| //Are there 12 bytes to read?
memcmp(TGAHeader, TGAcompare, sizeof(TGAHeader))!=0 || //Is the header correct?
fread(header, 1, sizeof(header), file)!=sizeof(header)) //Read next 6 bytes
{
fclose(file); //If anything else failed, close the file
errorLog.OutputError("Could not load %s correctly, general failure.", filename);
return false;
}
//save data into class member variables
unsigned int alphaWidth= header[1]*256+header[0]; //determine the image width
unsigned int alphaHeight= header[3]*256+header[2]; //determine image height
int alphaBpp= header[4];
if( alphaWidth<=0 || //if width <=0
alphaHeight<=0 || //or height<=0
alphaBpp!=8) //bpp not 8
{
fclose(file); //close the file
errorLog.OutputError("%s's height or width is less than zero, or the TGA is not 8 bpp.", filename);
return false;
}
//check it is the same size as the image
if(alphaWidth!=width || alphaHeight!=height)
{
errorLog.OutputError("%s is not the same size as the color texture", filename);
return false;
}
//make space for palette
unsigned char * palette=new unsigned char[256*3];
if(!palette)
{
errorLog.OutputError("Unable to allocate memory for palette");
return false;
}
//load the palette
fread(palette, 256*3, 1, file);
//we dont use the palette
delete [] palette;
palette=NULL;
//allocate space for alpha values
unsigned char * values=new unsigned char[width*height];
if(!values)
{
errorLog.OutputError("Unable to allocate memory for alpha values");
return false;
}
//load indices
fread(values, 1, alphaWidth*alphaHeight, file);
//close the file
fclose(file);
//now put in the alpha data
if(format==GL_RGBA)
{
for(unsigned int i=0; i<width*height; i++)
{
data[i*4+3]=values[i];
}
}
else if(format==GL_RGB)
{
unsigned char * tempData=new unsigned char[width*height*4];
if(!tempData)
{
errorLog.OutputError("Unable to allocate memory for Temporary Data");
return false;
}
for(unsigned int i=0; i<width*height; i++)
//.........这里部分代码省略.........
示例8: LoadUncompressedTrueColorTGA
//load an uncompressed TGA texture (24 or 32 bpp)
bool IMAGE::LoadUncompressedTrueColorTGA(char * filename)
{
unsigned char TGAheader[12]={0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Uncompressed TGA header
unsigned char TGAcompare[12]; //Used to compare TGA header
unsigned char header[6]; //First 6 useful bytes of the header
unsigned int bytesPerPixel; //bytes per pixel
unsigned int imageSize; //Stores Image size when in RAM
errorLog.OutputSuccess("Loading %s in LoadUncompressedTGA()", filename);
FILE * file = fopen(filename, "rb"); //Open the TGA file
if(file == NULL) //Does the file exist?
{
errorLog.OutputError("%s does not exist.", filename);
return false;
}
if( fread(TGAcompare, 1, sizeof(TGAcompare), file)!=sizeof(TGAcompare)|| //Are there 12 bytes to read?
memcmp(TGAheader, TGAcompare, sizeof(TGAheader))!=0 || //Is the header correct?
fread(header, 1, sizeof(header), file)!=sizeof(header)) //Read next 6 bytes
{
fclose(file); //If anything else failed, close the file
errorLog.OutputError("Could not load %s correctly, general failure.", filename);
return false;
}
//save data into class member variables
width= header[1]*256+header[0]; //determine the image width
height= header[3]*256+header[2]; //determine image height
bpp= header[4];
if( width<=0 || //if width <=0
height<=0 || //or height<=0
bpp!=24 && bpp!=32) //bpp not 24 or 32
{
fclose(file); //close the file
errorLog.OutputError("%s's height or width is less than zero, or the TGA is not 24 or 32 bpp.", filename);
return false;
}
//set format
if(bpp == 24)
format=GL_RGB;
else
format=GL_RGBA;
bytesPerPixel=bpp/8; //calc bytes per pixel
imageSize=width*height*bytesPerPixel; //calc memory required
data=new unsigned char[imageSize]; //reserve the memory for the data
if( data==NULL) //Does the storage memory exist?
{
errorLog.OutputError("Unable to allocate memory for %s image", filename);
fclose(file);
return false;
}
//read in the image data
if(fread(data, 1, imageSize, file)!=imageSize) //Does the image size match the required?
{ //If not
if(data) //If data loaded
delete [] data; //free memory
errorLog.OutputError("Could not read %s image data", filename);
fclose(file); //close file
return false;
}
fclose(file);
//data is in BGR format
//swap b and r
for(int i=0; i<(int)imageSize; i+=bytesPerPixel)
{
//repeated XOR to swap bytes 0 and 2
data[i] ^= data[i+2] ^= data[i] ^= data[i+2];
}
errorLog.OutputSuccess("Loaded %s correctly.", filename);
return true;
}
示例9: LoadCompressedTrueColorTGA
//load a compressed TGA texture (24 or 32 bpp)
bool IMAGE::LoadCompressedTrueColorTGA(char * filename)
{
unsigned char TGAheader[12]={0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Compressed TGA header
unsigned char TGAcompare[12]; //Used to compare TGA header
unsigned char header[6]; //First 6 useful bytes of the header
unsigned int bytesPerPixel; //bytes per pixel
unsigned int imageSize; //Stores Image size when in RAM
errorLog.OutputSuccess("Loading %s in LoadCompressedTGA()", filename);
FILE * file = fopen(filename, "rb"); //Open the TGA file
if(file == NULL) //Does the file exist?
{
errorLog.OutputError("%s does not exist.", filename);
return false;
}
if( fread(TGAcompare, 1, sizeof(TGAcompare), file)!=sizeof(TGAcompare)|| //Are there 12 bytes to read?
memcmp(TGAheader, TGAcompare, sizeof(TGAheader))!=0 || //Is the header correct?
fread(header, 1, sizeof(header), file)!=sizeof(header)) //Read next 6 bytes
{
fclose(file); //If anything else failed, close the file
errorLog.OutputError("Could not load %s correctly, general failure.", filename);
return false;
}
//save data into class member variables
width= header[1]*256+header[0]; //determine the image width
height= header[3]*256+header[2]; //determine image height
bpp= header[4];
if( width<=0 || //if width <=0
height<=0 || //or height<=0
bpp!=24 && bpp!=32) //bpp not 24 or 32
{
fclose(file); //close the file
errorLog.OutputError("%s's height or width is less than zero, or the TGA is not 24 or 32 bpp.", filename);
return false;
}
//set format
if(bpp == 24)
format=GL_RGB;
else
format=GL_RGBA;
bytesPerPixel=bpp/8; //calc bytes per pixel
imageSize=width*height*bytesPerPixel; //calc memory required
data=new unsigned char[imageSize]; //reserve the memory for the data
if(!data) //Does the storage memory exist?
{
errorLog.OutputError("Unable to allocate memory for %s image", filename);
fclose(file);
return false;
}
//read in the image data
int pixelCount = height*width;
int currentPixel= 0;
int currentByte = 0;
unsigned char * colorBuffer=new unsigned char[bytesPerPixel];
do
{
unsigned char chunkHeader=0;
if(fread(&chunkHeader, sizeof(unsigned char), 1, file) == 0)
{
errorLog.OutputError("Could not read RLE chunk header");
if(file)
fclose(file);
if(data)
delete [] data;
return false;
}
if(chunkHeader<128) //Read raw color values
{
chunkHeader++;
for(short counter=0; counter<chunkHeader; counter++)
{
if(fread(colorBuffer, 1, bytesPerPixel, file) != bytesPerPixel)
{
errorLog.OutputError("Unable to read %s image data", filename);
if(file)
fclose(file);
if(colorBuffer)
delete [] colorBuffer;
if(data)
delete [] data;
return false;
}
//.........这里部分代码省略.........
示例10: LoadPCX
//LoadPCX - load a .pcx texture - 256 color, paletted
bool IMAGE::LoadPCX(char * filename)
{
errorLog.OutputSuccess("Loading %s in LoadPCX()", filename);
//set bpp and format
bpp=24;
format=GL_RGB;
FILE * file;
file=fopen(filename, "rb");
if(!file)
{
errorLog.OutputError("Unable to open %s", filename);
return false;
}
//retrieve header, first 4 bytes, first 2 should be 0x0A0C
unsigned short header[2];
fread(header, 4, 1, file);
if(header[0]!=0x050A)
{
errorLog.OutputError("%s is not a legal .PCX file", filename);
fclose(file);
return false;
}
//retrieve minimum x value
int xMin=fgetc(file); //loword
xMin |= fgetc(file) << 8; //hiword
//retrieve minimum y value
int yMin=fgetc(file); //loword
yMin |= fgetc(file) << 8; //hiword
//retrieve maximum x value
int xMax=fgetc(file); //loword
xMax |= fgetc(file) << 8; //hiword
//retrieve maximum y value
int yMax=fgetc(file); //loword
yMax |= fgetc(file) << 8; //hiword
//calculate width and height
width = xMax-xMin+1;
height= yMax-yMin+1;
//allocate memory for pixel data (paletted)
unsigned char * pixelData=new unsigned char[width*height];
if(!pixelData)
{
errorLog.OutputError("Unable to allocate %d bytes for the image data of %s",
width*height, filename);
fclose(file);
return false;
}
//set file pointer to beginning of image data
fseek(file, 128, SEEK_SET);
//decode and store the pixel data
unsigned int index=0;
while(index<(width*height))
{
int c = getc(file);
if(c>0xBF)
{
int numRepeat = 0x3F & c;
c=getc(file);
for(int i=0; i<numRepeat; i++)
pixelData[index++] = c;
}
else
pixelData[index++] = c;
fflush(stdout);
}
//allocate memory for the image palette
unsigned char * paletteData = new unsigned char[768];
//the palette is the last 769 bytes of the file
fseek(file, -769, SEEK_END);
//retrieve first character, should be equal to 12
int c=getc(file);
if(c!=12)
{
errorLog.OutputError("%s is not a legal .PCX file - the palette data has an illegal header, %d",
filename, c);
fclose(file);
return false;
}
//read and store the palette
//.........这里部分代码省略.........
示例11: fopen
//load an 8 bit uncompressed paletted TGA
bool IMAGE::LoadUncompressed8BitTGA(char * filename)
{
unsigned char TGAHeader[12]={0, 1, 1, 0, 0, 0, 1, 24, 0, 0, 0, 0};
unsigned char TGAcompare[12]; //Used to compare TGA header
unsigned char header[6]; //First 6 useful bytes of the header
errorLog.OutputSuccess("Loading %s in LoadUncompressed8BitTGA()", filename);
FILE * file = fopen(filename, "rb"); //Open the TGA file
if(file == NULL) //Does the file exist?
{
errorLog.OutputError("%s does not exist.", filename);
return false;
}
if( fread(TGAcompare, 1, sizeof(TGAcompare), file)!=sizeof(TGAcompare)|| //Are there 12 bytes to read?
memcmp(TGAHeader, TGAcompare, sizeof(TGAHeader))!=0 || //Is the header correct?
fread(header, 1, sizeof(header), file)!=sizeof(header)) //Read next 6 bytes
{
fclose(file); //If anything else failed, close the file
errorLog.OutputError("Could not load %s correctly, general failure.", filename);
return false;
}
//save data into class member variables
width= header[1]*256+header[0]; //determine the image width
height= header[3]*256+header[2]; //determine image height
bpp= header[4];
if( width<=0 || //if width <=0
height<=0 || //or height<=0
bpp!=8) //bpp not 8
{
fclose(file); //close the file
errorLog.OutputError("%s's height or width is less than zero, or the TGA is not 8 bpp.", filename);
return false;
}
//set format
format=GL_RGB;
//make space for palette
unsigned char * palette=new unsigned char[256*3];
if(!palette)
{
errorLog.OutputError("Unable to allocate memory for palette");
return false;
}
//load the palette
fread(palette, 256*3, 1, file);
//allocate space for color indices
unsigned char * indices=new unsigned char[width*height];
if(!indices)
{
errorLog.OutputError("Unable to allocate memory for indices");
return false;
}
//load indices
fread(indices, 1, width*height, file);
//close the file
fclose(file);
//allocate space for the image data
data=new unsigned char[width*height*3];
if(!data)
{
fclose(file);
errorLog.OutputError("Unable to allocate memory for %s", filename);
return false;
}
//calculate the color values
for(unsigned int currentRow=0; currentRow<height; currentRow++)
{
for(unsigned int i=0; i<width; i++)
{
data[(currentRow*width+i)*3+0]=palette[indices[currentRow*width+i]*3+2];
data[(currentRow*width+i)*3+1]=palette[indices[currentRow*width+i]*3+1];
data[(currentRow*width+i)*3+2]=palette[indices[currentRow*width+i]*3+0];//BGR
}
}
errorLog.OutputSuccess("Loaded %s correctly.", filename);
return true;
}
示例12: Init
bool WINDOW::Init(char * windowTitle,
int newWidth, int newHeight,
int newColorBits, int newDepthBits, int newStencilBits,
int fullscreenflag)
//CREATE WINDOW
{
WNDCLASS wc; //windows class structure
DWORD dwExStyle; //extended style info.
DWORD dwStyle; //style info
//set class's member variables
title=windowTitle;
width=newWidth;
height=newHeight;
colorBits=newColorBits;
depthBits=newDepthBits;
stencilBits=newStencilBits;
//set class's fullscreen flag
if(fullscreenflag == FULL_SCREEN)
{
fullscreen=true;
}
if(fullscreenflag == WINDOWED_SCREEN)
{
fullscreen=false;
}
if(fullscreenflag == CHOOSE_SCREEN) //Ask user if fullscreen
{
if(MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?","Start FullScreen",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=false; //If answered no
}
else
{
fullscreen=true; //if answered yes
}
}
RECT WindowRect; //grab rect. upper left/lower right values
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;
hInstance= GetModuleHandle(NULL); //Grab an instance for window
wc.style= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
//window style: redraw on move, own DC
wc.lpfnWndProc= (WNDPROC) WndProc; //Wndproc handles messages
wc.cbClsExtra= 0;
wc.cbWndExtra= 0; //no extra window data
wc.hInstance= hInstance; //Set the instance
wc.hIcon= LoadIcon(NULL, IDI_WINLOGO); //load default icon
wc.hCursor= LoadCursor(NULL, IDC_ARROW); //Load arrow cursor
wc.hbrBackground=NULL; //No background rqd for GL
wc.lpszMenuName=NULL; //No menu
wc.lpszClassName="OpenGL"; //set class name
if(!RegisterClass(&wc)) //try to register class
{
errorLog.OutputError("Failed to register the window class");
return FALSE;
}
else
errorLog.OutputSuccess("Window Class Registered");
if(fullscreen) //try to set up fullscreen?
{
DEVMODE dmScreenSettings; //Device mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
//clear memory
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
//size of devmode structure
dmScreenSettings.dmPelsWidth=width; //selected width
dmScreenSettings.dmPelsHeight=height; //selected height
dmScreenSettings.dmBitsPerPel=colorBits; //selected bpp
dmScreenSettings.dmFields=DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
//try to set mode.CDS_FULLSCREEN removes start bar
{
//If mode fails, give 2 options, quit or run in window
if(MessageBox(NULL, "The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?",title, MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; //if "yes", try windowed
}
else
{
//tell user program is closing
errorLog.OutputError("Program Closed, As Fullscreen Mode Not Supported.");
return FALSE; //exit and return FALSE
}
}
}
if (fullscreen) //still fullscreen?
{
dwExStyle=WS_EX_APPWINDOW; //window extended style
//.........这里部分代码省略.........
示例13: Load
////////////////////BSP::Load///////////////
////////////////////////////////////////////
bool BSP::Load(char * filename, int curveTesselation)
{
FILE * file;
file=fopen(filename, "rb");
if(!file)
{
errorLog.OutputError("Unable to open %s", filename);
return false;
}
//read in header
fread(&header, sizeof(BSP_HEADER), 1, file);
//check header data is correct
if( header.string[0]!='I' || header.string[1]!='B' ||
header.string[2]!='S' || header.string[3]!='P' ||
header.version !=0x2E )
{
errorLog.OutputError("%s is not a version 0x2E .bsp map file", filename);
return false;
}
//Load in vertices
if(!LoadVertices(file))
return false;
//Load in mesh indices
//Calculate number of indices
int numMeshIndices=header.directoryEntries[bspMeshIndices].length/sizeof(int);
//Create space
meshIndices=new int[numMeshIndices];
if(!meshIndices)
{
errorLog.OutputError("Unable to allocate memory for %d mesh indices", numMeshIndices);
return false;
}
//read in the mesh indices
fseek(file, header.directoryEntries[bspMeshIndices].offset, SEEK_SET);
fread(meshIndices, header.directoryEntries[bspMeshIndices].length, 1, file);
//Load in faces
if(!LoadFaces(file, curveTesselation))
return false;
//Load textures
if(!LoadTextures(file))
return false;
//Load Lightmaps
if(!LoadLightmaps(file))
return false;
//Load BSP Data
if(!LoadBSPData(file))
return false;
//Load in entity string
entityString=new char[header.directoryEntries[bspEntities].length];
if(!entityString)
{
errorLog.OutputError( "Unable to allocate memory for %d length entity string",
header.directoryEntries[bspEntities].length);
return false;
}
//Go to entity string in file
fseek(file, header.directoryEntries[bspEntities].offset, SEEK_SET);
fread(entityString, 1, header.directoryEntries[bspEntities].length, file);
//Output the entity string
//errorLog.OutputSuccess("Entity String: %s", entityString);
fclose(file);
errorLog.OutputSuccess("%s Loaded successfully", filename);
return true;
}
示例14: SaveScreenshot
void WINDOW::SaveScreenshot(void)
{
FILE * file;
//first calculate the filename to save to
char filename[32];
for(int i=0; i<1000; i++)
{
sprintf(filename, "screen%03d.tga", i);
//try opening this file - if not possible, use this filename
file=fopen(filename, "rb");
if(!file)
{
break;
}
//otherwise, the file exists, try next, except if this is the last one
fclose(file);
if(i==999)
{
errorLog.OutputError("No space to save screenshot - 0-999 exist");
return;
}
}
errorLog.OutputSuccess("Saving %s", filename);
GLubyte TGAheader[12]={0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Uncompressed TGA header
GLubyte infoHeader[6];
unsigned char * data=new unsigned char[4*width*height];
if(!data)
{
errorLog.OutputError("Unable to allocate memory for screen data");
return;
}
//read in the screen data
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
//data needs to be in BGR format
//swap b and r
for(int i=0; i<(int)width*height*4; i+=4)
{
//repeated XOR to swap bytes 0 and 2
data[i] ^= data[i+2] ^= data[i] ^= data[i+2];
}
//open the file
file = fopen(filename, "wb");
//save header
fwrite(TGAheader, 1, sizeof(TGAheader), file);
//save info header
infoHeader[0]=(width & 0x00FF);
infoHeader[1]=(width & 0xFF00) >> 8;
infoHeader[2]=(height & 0x00FF);
infoHeader[3]=(height & 0xFF00) >> 8;
infoHeader[4]=32;
infoHeader[5]=0;
//save info header
fwrite(infoHeader, 1, sizeof(infoHeader), file);
//save the image data
fwrite(data, 1, width*height*4, file);
fclose(file);
errorLog.OutputSuccess("Saved Screenshot: %s", filename);
return;
}
示例15: Init
bool PBUFFER::Init( int newWidth, int newHeight,
int newColorBits, int newDepthBits, int newStencilBits,
int numExtraIAttribs, int * extraIAttribList, int * flags)
{
//Check for pbuffer support
if( !WGL_ARB_extensions_string_supported ||
!WGL_ARB_pixel_format_supported ||
!WGL_ARB_pbuffer_supported)
{
errorLog.OutputError("Extension required for pbuffer unsupported");
return false;
}
//set class's member variables
width=newWidth;
height=newHeight;
colorBits=newColorBits;
depthBits=newDepthBits;
stencilBits=newStencilBits;
//Get the current device context
HDC hCurrentDC=wglGetCurrentDC();
if(!hCurrentDC)
{
errorLog.OutputError("Unable to get current Device Context");
return false;
}
//choose pixel format
GLint pixelFormat;
const int standardIAttribList[]={ WGL_DRAW_TO_PBUFFER_ARB, 1,
WGL_COLOR_BITS_ARB, colorBits,
WGL_ALPHA_BITS_ARB, colorBits==32 ? 8 : 0,
WGL_DEPTH_BITS_ARB, depthBits,
WGL_STENCIL_BITS_ARB, stencilBits};
const float fAttribList[]={
0};
//add the extraIAttribList to the standardIAttribList
int * iAttribList=new int[sizeof(standardIAttribList)/sizeof(int)+numExtraIAttribs*2+1];
if(!iAttribList)
{
errorLog.OutputError("Unable to allocate space for iAttribList");
return false;
}
memcpy( iAttribList, standardIAttribList, sizeof(standardIAttribList));
memcpy( iAttribList+sizeof(standardIAttribList)/sizeof(int),
extraIAttribList, numExtraIAttribs*2*sizeof(int)+sizeof(int));
//Choose pixel format
unsigned int numFormats;
if(!wglChoosePixelFormatARB(hCurrentDC, iAttribList, fAttribList, 1,
&pixelFormat, &numFormats))
{
errorLog.OutputError("Unable to find a pixel format for the pbuffer");
return false;
}
//Create the pbuffer
hBuffer=wglCreatePbufferARB(hCurrentDC, pixelFormat, width, height, flags);
if(!hBuffer)
{
errorLog.OutputError("Unable to create pbuffer");
return false;
}
//Get the pbuffer's device context
hDC=wglGetPbufferDCARB(hBuffer);
if(!hDC)
{
errorLog.OutputError("Unable to get pbuffer's device context");
return false;
}
//Create a rendering context for the pbuffer
hRC=wglCreateContext(hDC);
if(!hRC)
{
errorLog.OutputError("Unable to create pbuffer's rendering context");
return false;
}
//Set and output the actual pBuffer dimensions
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_WIDTH_ARB, &width);
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_HEIGHT_ARB, &height);
errorLog.OutputSuccess("Pbuffer Created: (%d x %d)", width, height);
return TRUE; //success!
}