Archived

This topic is now archived and is closed to further replies.

Transparency with bitmap resource as a texture

This topic is 5004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey, this is my first time here, and I think you might like to know that i am the n00biest of all n00bs. Anyway, I''ve been programming this little cube with a bitmap texture as a win32 resource in msvc++ 6. My problem is, I can''t get the transparency to work. Heres my LoadGLTextures:
int LoadGLTextures()									// Load Bitmaps And Convert To Textures

{
	
HWND hwnd;
	int Status=TRUE;									// Status Indicator


   // load bitmap from resource file

   HBITMAP bitmap  = LoadBitmap(GetModuleHandle(NULL), 
      MAKEINTRESOURCE(IDB_BITMAP2));


   // setup 24 bits bitmap structure

   // works on 8 bits bitmaps also!



   BITMAPINFO info;
   BITMAPINFOHEADER header;
   header.biSize = sizeof(BITMAPINFOHEADER);     
   header.biWidth = 256;     
   header.biHeight = 256; 
   header.biPlanes = 1;     
   header.biBitCount = 24;     
   header.biCompression = BI_RGB;
   header.biSizeImage = 0;     
   header.biClrUsed = 0;     
   header.biClrImportant = 0; 

   info.bmiHeader = header;
   info.bmiColors->rgbRed      = NULL;
   info.bmiColors->rgbGreen    = NULL;
   info.bmiColors->rgbBlue     = NULL;
   info.bmiColors->rgbReserved = NULL;


   // store bitmap data in a vector

   const int size = 256*256*3;
   unsigned char data[size];  

   HDC hdc = GetDC(hWnd);
      GetDIBits(hdc, bitmap,  0, 256,  &data,  &info, DIB_RGB_COLORS);
  
	  ReleaseDC(hWnd, hdc);
  


   // convert from BGR to RGB

   unsigned char buff;
   for(int i=0; i<256*256; i++)
   {
      buff = data[i*3];
      if(i>=3)
      {
         data[i*3]   = data[i*3+2];
         data[i*3+2] = buff;
      }
   }
 unsigned char  *src_bitmap = data;
   unsigned char *alpha_bitmap = (unsigned char *)malloc(((256)*(256)) *4) ;
   for (unsigned int src = 0, dst = 0; src < (256)*3; src +=3, dst +=4)
{
// if the pixel is black, set the alpha to 0. Otherwise, set it to 255.

	
	if( src_bitmap[src] == 0xFF && src_bitmap[src+1] == 0 && src_bitmap[src+2] == 0xFF )
{
alpha_bitmap[dst+3] = 0;
PostQuitMessage(0); //I tell it to quit, and it WONT!

}
else
alpha_bitmap[dst+3] = 0xFF;

// copy pixel data over

alpha_bitmap[dst] = src_bitmap[src];
alpha_bitmap[dst+1] = src_bitmap[src+1];
alpha_bitmap[dst+2] = src_bitmap[src+2];
}

   // create one texture

   glGenTextures(1, &m_texture[0]);
				
   // select texture

   glBindTexture(GL_TEXTURE_2D, m_texture[0]);

	
   // SetTextureParameters

		glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);

   gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 256, 256,
GL_RGBA, GL_UNSIGNED_BYTE, alpha_bitmap);
		// generate texture

   glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
//free all the stuff, etc.



and within my DrawScene(), i have:
   
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0);
right before i draw my cube. My cube''s texture has a large pink(255,0,255) square on it that should go transparent, but it doesn''t. Help me, please. Thank you all! http://www.WoodmanStudios.tk http://www.WoodmanStudios.tk

Share this post


Link to post
Share on other sites
first: PostQuitMessage does not quit... it just tells windows to inform you about it in the next run of your message loop ;=)

and for your problem.
enabling alpha blending is nice but you first have to set the blending modes to... should be:
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

have a look at SetRenderState, there you find it

EDIT: you have btw used AlphaTest function which is not the same as AlphaBlending. Alpha test refuses drawing pixels depending on an alpha value but you want to blend it using the colors on the screen

[edited by - RPTD on March 28, 2004 5:33:20 PM]

Share this post


Link to post
Share on other sites
Yeah, that reply makes sense only in a D3D context, not an OpenGL context.

One of the problems is probably that you''re calling glTexImage2D() after you''ve called gluBuild2DMipmaps(). The glu functions calls glTexImage2D() on all your mip map levels (including 0) so that call overwrites part of what glu did.

Also, you''re passing TexImage2D() the RGB data (without alpha), not the RGBA data (with alpha) which would account for your alpha not coming through.

PostQuitMessage() posts a message to the Windows event loop. It''s un-clear whether what you actually want "ExitProcess()" at that point, or perhaps "break;" (depending on what it is you want to quit out of!)

Share this post


Link to post
Share on other sites
quote:
Original post by SERPENT
hmm. do i need diect3d (d3d) in order to use those?


yeah... sorry guys... was kinda sleepy when i wrote this but in fact it's the same. you have to set the source/dest blend function in ogl too, just like this:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);



EDIT: i've done this in my code. perhaps it helps you.
// copy data to temporary texture-data
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, vTex->width, vTex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, vTexData);


[edited by - RPTD on March 28, 2004 6:12:52 PM]

Share this post


Link to post
Share on other sites
darn. it still isn't working. heres my textures again:

int LoadGLTextures() // Load Bitmaps And Convert To Textures

{

HWND hwnd;
int Status=TRUE; // Status Indicator


// load bitmap from resource file

HBITMAP bitmap = LoadBitmap(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP2));


// setup 24 bits bitmap structure

// works on 8 bits bitmaps also!



BITMAPINFO info;
BITMAPINFOHEADER header;
header.biSize = sizeof(BITMAPINFOHEADER);
header.biWidth = 256;
header.biHeight = 256;
header.biPlanes = 1;
header.biBitCount = 24;
header.biCompression = BI_RGB;
header.biSizeImage = 0;
header.biClrUsed = 0;
header.biClrImportant = 0;

info.bmiHeader = header;
info.bmiColors->rgbRed = NULL;
info.bmiColors->rgbGreen = NULL;
info.bmiColors->rgbBlue = NULL;
info.bmiColors->rgbReserved = NULL;


// store bitmap data in a vector

const int size = 256*256*3;
unsigned char data[size];

HDC hdc = GetDC(hWnd);
GetDIBits(hdc, bitmap, 0, 256, &data, &info, DIB_RGB_COLORS);

ReleaseDC(hWnd, hdc);



// convert from BGR to RGB

unsigned char buff;
for(int i=0; i<256*256; i++)
{
buff = data[i*3];
if(i>=3)
{
data[i*3] = data[i*3+2];
data[i*3+2] = buff;
}
}
unsigned char *src_bitmap = data;
unsigned char *alpha_bitmap = (unsigned char *)malloc(((256)*(256)) *4) ;
for (unsigned int src = 0, dst = 0; src < (256)*3; src +=3, dst +=4)
{
// if the pixel is black, set the alpha to 0. Otherwise, set it to 255.


if( src_bitmap[src] == 0xFF && src_bitmap[src+1] == 0 && src_bitmap[src+2] == 0xFF )
{
alpha_bitmap[dst+3] = 0;
PostQuitMessage(0);
}
else
alpha_bitmap[dst+3] = 0xFF;

alpha_bitmap[dst+3] = 0;

// copy pixel data over

alpha_bitmap[dst] = src_bitmap[src];
alpha_bitmap[dst+1] = src_bitmap[src+1];
alpha_bitmap[dst+2] = src_bitmap[src+2];
}

// create one texture

glGenTextures(1, &m_texture[0]);

// select texture

glBindTexture(GL_TEXTURE_2D, m_texture[0]);


// SetTextureParameters

glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);

gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 256, 256,
GL_RGBA, GL_UNSIGNED_BYTE, alpha_bitmap);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
//free stuff yadayada



and here's my blitting:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
// Back Face

glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
// Top Face

glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
// Bottom Face

glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face

glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
// Left Face

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();
return true;

EDIT: your teximage2d still gives me an illigal error.
http://www.WoodmanStudios.tk

[edited by - SERPENT on March 28, 2004 6:16:29 PM]

Share this post


Link to post
Share on other sites
OK, here is my entire source. It''s a little program where you can rotate a cube(i''m testing opengl out for the first time.) Please, somebody, tell me what i''m doing wrong! I beg of you! I will be your best friend!!

here goes..

#include <windows.h> // Header File For Windows

#include <gl\gl.h> // Header File For The OpenGL32 Library

#include <gl\glu.h> // Header File For The GLu32 Library

#include <gl\glaux.h> // Header File For The Glaux Library

#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include "globals.h"
#include "resource.h"

HDC hDC=NULL; // Private GDI Device Context

HGLRC hRC=NULL; // Permanent Rendering Context

HWND hWnd=NULL; // Holds Our Window Handle

HINSTANCE hInstance; // Holds The Instance Of The Application

GLuint base;
bool keys[256]; // Array Used For The Keyboard Routine

bool active=TRUE; // Window Active Flag Set To TRUE By Default

bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

bool trans = true;
bool wireframe = false;
bool TPressed = false;
bool WPressed = false;
float col1,col2,col3;
bool colorup = true;
GLfloat rtri; // Angle For The Triangle ( NEW )

GLfloat rquad; // Angle For The Quad ( NEW )

GLfloat cnt1; // 1st Counter Used To Move Text & For Coloring

GLfloat cnt2;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc


GLuint m_texture[1]; // Storage For One Texture ( NEW )


AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image

{
FILE *File=NULL; // File Handle


if (!Filename) // Make Sure A Filename Was Given

{
return NULL; // If Not Return NULL

}

File=fopen(Filename,"r"); // Check To See If The File Exists


if (File) // Does The File Exist?

{
fclose(File); // Close The Handle

return auxDIBImageLoad(MAKEINTRESOURCE(IDB_BITMAP2)); // Load The Bitmap And Return A Pointer

}

return NULL; // If Load Failed Return NULL

}


int LoadGLTextures() // Load Bitmaps And Convert To Textures

{

HWND hwnd;
int Status=TRUE; // Status Indicator


// load bitmap from resource file

HBITMAP bitmap = LoadBitmap(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP2));


// setup 24 bits bitmap structure

// works on 8 bits bitmaps also!



BITMAPINFO info;
BITMAPINFOHEADER header;
header.biSize = sizeof(BITMAPINFOHEADER);
header.biWidth = 256;
header.biHeight = 256;
header.biPlanes = 1;
header.biBitCount = 24;
header.biCompression = BI_RGB;
header.biSizeImage = 0;
header.biClrUsed = 0;
header.biClrImportant = 0;

info.bmiHeader = header;
info.bmiColors->rgbRed = NULL;
info.bmiColors->rgbGreen = NULL;
info.bmiColors->rgbBlue = NULL;
info.bmiColors->rgbReserved = NULL;


// store bitmap data in a vector

const int size = 256*256*3;
unsigned char data[size];

HDC hdc = GetDC(hWnd);
GetDIBits(hdc, bitmap, 0, 256, &data, &info, DIB_RGB_COLORS);

ReleaseDC(hWnd, hdc);



// convert from BGR to RGB

unsigned char buff;
for(int i=0; i<256*256; i++)
{
buff = data[i*3];
if(i>=3)
{
data[i*3] = data[i*3+2];
data[i*3+2] = buff;
}
}
unsigned char *src_bitmap = data;
unsigned char *alpha_bitmap = (unsigned char *)malloc(((256)*(256)) *4) ;
for (unsigned int src = 0, dst = 0; src < (256)*3; src +=3, dst +=4)
{
// if the pixel is black, set the alpha to 0. Otherwise, set it to 255.


if( src_bitmap[src] == 0xFF && src_bitmap[src+1] == 0 && src_bitmap[src+2] == 0xFF )
{
alpha_bitmap[dst+3] = 0;
PostQuitMessage(0);
}
else
alpha_bitmap[dst+3] = 0xFF;

alpha_bitmap[dst+3] = 0;

// copy pixel data over

alpha_bitmap[dst] = src_bitmap[src];
alpha_bitmap[dst+1] = src_bitmap[src+1];
alpha_bitmap[dst+2] = src_bitmap[src+2];
}

// create one texture

glGenTextures(1, &m_texture[0]);

// select texture

glBindTexture(GL_TEXTURE_2D, m_texture[0]);


// SetTextureParameters


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_RGBA8, GL_UNSIGNED_BYTE, &data);

gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 256, 256,
GL_RGB, GL_UNSIGNED_BYTE, alpha_bitmap);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);

// generate texture


// free (alpha_bitmap);

/* AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL

TextureImage[0]=LoadBMP("test.bmp");
unsigned char *alpha_bitmap = (unsigned char *)malloc( ((TextureImage[0]->sizeX*TextureImage[0]->sizeY) * 4) );

unsigned char *src_bitmap = TextureImage[0]->data;

// Load The Bitmap, Check For Errors, If Bitmap''s Not Found Quit
if (TextureImage[0]=LoadBMP("test.bmp"))
{
Status=TRUE; // Set The Status To TRUE


for (unsigned int src = 0, dst = 0; src < (TextureImage[0]->sizeX*TextureImage[0]->sizeY)*3; src +=3, dst +=4)
{
// if the pixel is black, set the alpha to 0. Otherwise, set it to 255.

if( src_bitmap[src] == 0xFF && src_bitmap[src+1] == 0 && src_bitmap[src+2] == 0xFF )
{
alpha_bitmap[dst+3] = 0;
}
else
alpha_bitmap[dst+3] = 0xFF;

// copy pixel data over
alpha_bitmap[dst] = src_bitmap[src];
alpha_bitmap[dst+1] = src_bitmap[src+1];
alpha_bitmap[dst+2] = src_bitmap[src+2];
}

glGenTextures(1, &texture[0]); // Create The Texture

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
*/


/* gluBuild2DMipmaps(GL_TEXTURE_2D, 4, TextureImage[0]->sizeX, TextureImage[0]->sizeY,
GL_RGBA, GL_UNSIGNED_BYTE, alpha_bitmap);
}

if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}

free(TextureImage[0]);
free( alpha_bitmap ); // Free The Image Structure
}*/


return Status; // Return The Status

}

float xrot;
float yrot;
GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine

{
char text[256]; // Holds Our String

va_list ap; // Pointer To List Of Arguments


if (fmt == NULL) // If There''s No Text

return; // Do Nothing


va_start(ap, fmt); // Parses The String For Variables

vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers

va_end(ap); // Results Are Stored In Text


glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits

glListBase(base - 32); // Sets The Base Character to 32

glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text

glPopAttrib(); // Pops The Display List Bits

}
/*unsigned int iTexture;

int LoadGLTextures()
{
AUX_RGBImageRec *AUXTextureImage = 0;

// Open the file
FILE *hFile = fopen("test.bmp","r");


// Does file exist ?
if (hFile)
{
// Close the stream
fclose(hFile);

// Load bitmap
AUXTextureImage = auxDIBImageLoad("test.bmp");

unsigned char *alpha_bitmap = (unsigned char *)malloc( ((AUXTextureImage->sizeX*AUXTextureImage->sizeY) * 4) );

unsigned char *src_bitmap = AUXTextureImage->data;


if( src_bitmap == NULL || alpha_bitmap == NULL )
{
MessageBox( NULL, "Image not loaded", "ERROR", MB_OK );

}

for (unsigned int src = 0, dst = 0; src < (AUXTextureImage->sizeX*AUXTextureImage->sizeY)*3; src +=3, dst +=4)
{
// if the pixel is black, set the alpha to 0. Otherwise, set it to 255.
if( src_bitmap[src] == 0xFF && src_bitmap[src+1] == 0 && src_bitmap[src+2] == 0xFF )
{
alpha_bitmap[dst+3] = 0;
}
else
alpha_bitmap[dst+3] = 0xFF;

// copy pixel data over
alpha_bitmap[dst] = src_bitmap[src];
alpha_bitmap[dst+1] = src_bitmap[src+1];
alpha_bitmap[dst+2] = src_bitmap[src+2];
}


// Create one texture
glGenTextures(1, &iTexture);

// Make the texture the current one
glBindTexture(GL_TEXTURE_2D, iTexture);

// Texture parameters
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

// Build mip-maps
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, AUXTextureImage->sizeX, AUXTextureImage->sizeY,
GL_RGBA, GL_UNSIGNED_BYTE, alpha_bitmap);

free( alpha_bitmap );

}
else
// Failed
return FALSE;

// Does texture exist ?
if (AUXTextureImage)
{
// If texture image exists
if (AUXTextureImage->data)
// Free the texture image memory
free(AUXTextureImage->data);
else
// Failed
return FALSE;

// free the image structure
free(AUXTextureImage);
}
else
// Failed
return FALSE;



}*/


int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glLoadIdentity();
glTranslatef(0.0,0.0,-10.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
if(wireframe == true)
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
else
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
if(trans == true){
glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER,0);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

}
else{
glDisable(GL_ALPHA_TEST);

}
// Front Face

glColor3ub(col1, col2, col3);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
// Back Face

glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
// Top Face

glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
// Bottom Face

glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face

glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
// Left Face

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();

if(GetAsyncKeyState(''B'')){
if(colorup == true){
col1 += 0.5f;
col2 += 0.5f;
col3 += 0.3f;
}
else
{
col1 -= 0.5f;
col2 -=0.5f;
col3 -=0.3f;
}
}
if(col1 >= 255.0f)
colorup = false;
if(col1 <= 100.0f || col2 <= 100.0f || col3 <= 100.0f)
colorup = true;

if(GetAsyncKeyState(VK_DOWN))
xrot += 0.2f;
if(GetAsyncKeyState(VK_UP))
xrot -= 0.2f;
if(GetAsyncKeyState(VK_LEFT))
yrot -= 0.2f;
if(GetAsyncKeyState(VK_RIGHT))
yrot += 0.2f;
if(GetAsyncKeyState(''T'') && TPressed == false)
{ if(trans == true)trans = false;
else trans = true;
TPressed = true;
}
if(!GetAsyncKeyState(''T''))
TPressed = false;
if(GetAsyncKeyState(''W'') && WPressed == false)
{
if(wireframe == true)wireframe = false;
else wireframe = true;
WPressed = true;
}
if(!GetAsyncKeyState(''W''))
WPressed = false;



glTranslatef(0.0f,0.0f,-1.0f);
//glColor3f(255.0f,0.0f,0.0f);

glRasterPos2f(-0.45f,-0.4f);
glPrint("%f,%f",xrot,yrot);
//glColor3ub(255, 255, 255);


glLoadIdentity();
glTranslatef(0.0f,0.0f,-1.0f);
glColor3f(0.0f,1.0f,1.0f);
glRasterPos2f(-0.4f,-0.4f);
glPrint("3-D C++ OpenGL Engine Test By Tom Woodman");

glLoadIdentity();
glTranslatef(0.0f,0.0f,-1.0f);
glColor3f(0.0f,1.0f,1.0f);
glRasterPos2f(-0.23f,0.385f);
glPrint("Use Arrow Keys To Rotate");


glLoadIdentity();
glTranslatef(0.0f,0.0f,-1.0f);
//glColor3f(10.0f,0.0f,1.0f);

glRasterPos2f(-0.55,0.3);
glPrint("[T] Transparency");
glRasterPos2f(-0.55,0.26);
glPrint("[W] Wireframe Mode");
glRasterPos2f(-0.55,0.22);
glPrint("[B] Brightness");
glRasterPos2f(-0.55,0.18);
glPrint("[F] Fullscreen Mode");
glRasterPos2f(-0.55,0.14);
glPrint("[E] Exit");


return true; // Keep Going

}
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font

{
HFONT font; // Windows Font ID

HFONT oldfont; // Used For Good House Keeping


base = glGenLists(96); // Storage For 96 Characters


font = CreateFont( -24, // Height Of Font

0, // Width Of Font

0, // Angle Of Escapement

0, // Orientation Angle

FW_BOLD, // Font Weight

FALSE, // Italic

FALSE, // Underline

FALSE, // Strikeout

ANSI_CHARSET, // Character Set Identifier

OUT_TT_PRECIS, // Output Precision

CLIP_DEFAULT_PRECIS, // Clipping Precision

ANTIALIASED_QUALITY, // Output Quality

FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch

"Courier New"); // Font Name


oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want

wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32

SelectObject(hDC, oldfont); // Selects The Font We Want

DeleteObject(font); // Delete The Font

}

GLvoid KillFont(GLvoid) // Delete The Font List

{
glDeleteLists(base, 96); // Delete All 96 Characters

}




GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window

{
if (height==0) // Prevent A Divide By Zero By

{
height=1; // Making Height Equal One

}

glViewport(0,0,width,height); // Reset The Current Viewport


glMatrixMode(GL_PROJECTION); // Select The Projection Matrix

glLoadIdentity(); // Reset The Projection Matrix


// Calculate The Aspect Ratio Of The Window

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

glLoadIdentity(); // Reset The Modelview Matrix

}

int InitGL(GLvoid) // All Setup For OpenGL Goes Here

{

col1 = 255;
col2 = 255;
col3 = 255;
glEnable(GL_TEXTURE_2D);
//glShadeModel(GL_SMOOTH); // Enable Smooth Shading

glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background

glClearDepth(1.0f); // Depth Buffer Setup

glEnable(GL_DEPTH_TEST); // Enables Depth Testing

glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

BuildFont();
if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )

{
return FALSE; // If Texture Didn''t Load Return FALSE ( NEW )

}
return TRUE; // Initialization Went OK

}

/*int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);// Reset The Current Modelview Matrix
/*glTranslatef(0.0f,0.0f,-1.0f); // Move One Unit Into The Screen
// Pulsing Colors Based On Text Position

// Position The Text On The Screen
glRasterPos2f(0,0);
glPrint("penisssss"); // Print GL Text To The Screen

glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
// glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW )
// Done Drawing The Triangle
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,rtri); // Move Right 1.5 Units And Into The Screen 6.0
glRotatef(rquad,0.0f,0.0f,1.0f); // Rotate The Quad On The X axis ( NEW )
// Set The Color To Blue One Time Only
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0);

glBindTexture(GL_TEXTURE_2D, iTexture); // Select Our Texture
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-4.8f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-3.0f,-1.0f, 0.0f); // Bottom Left
glEnd();// Done Drawing The Quad
glTranslatef(2.0f,0.0f,rtri+50); // Move Right 1.5 Units And Into The Screen 6.0
glRotatef(rquad,0.0f,0.0f,1.0f); // Rotate The Quad On The X axis ( NEW )
* // Set The Color To Blue One Time Only


// Select Our Texture
// glColor3f(1.0f,0.0f,0.0f);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0);
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-3.8f, 1.0f, 0.0f); // Top Left
glVertex3f( 4.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 4.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-3.0f,-1.0f, 0.0f); // Bottom Left
glEnd();
rtri-=0.01f; // Increase The Rotation Variable For The Triangle ( NEW )
if(rtri < -100.0f)
rtri = 0;
rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW )





//glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glEnd();

return true; // Keep Going
}*/


GLvoid KillGLWindow(GLvoid) // Properly Kill The Window

{
if (fullscreen) // Are We In Fullscreen Mode?

{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop

ShowCursor(TRUE); // Show Mouse Pointer

}

if (hRC) // Do We Have A Rendering Context?

{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?

{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}

if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?

{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL; // Set RC To NULL

}

if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC

{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL

}

if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?

{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL

}

if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class

{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL

}
KillFont();
}

/* This Code Creates Our OpenGL Window. Parameters Are: *
* title - Title To Appear At The Top Of The Window *
* width - Width Of The GL Window Or Fullscreen Mode *
* height - Height Of The GL Window Or Fullscreen Mode *
* bits - Number Of Bits To Use For Color (8/16/24/32) *
* fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */


BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match

WNDCLASS wc; // Windows Class Structure

DWORD dwExStyle; // Window Extended Style

DWORD dwStyle; // Window Style

RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values

WindowRect.left=(long)0; // Set Left Value To 0

WindowRect.right=(long)width; // Set Right Value To Requested Width

WindowRect.top=(long)0; // Set Top Value To 0

WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height


fullscreen=fullscreenflag; // Set The Global Fullscreen Flag


hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window

wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.

wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages

wc.cbClsExtra = 0; // No Extra Window Data

wc.cbWndExtra = 0; // No Extra Window Data

wc.hInstance = hInstance; // Set The Instance

wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon

wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer

wc.hbrBackground = NULL; // No Background Required For GL

wc.lpszMenuName = NULL; // We Don''t Want A Menu

wc.lpszClassName = "OpenGL"; // Set The Class Name


if (!RegisterClass(&wc)) // Attempt To Register The Window Class

{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

if (fullscreen) // Attempt Fullscreen Mode?

{
DEVMODE dmScreenSettings; // Device Mode

memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory''s Cleared

dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure

dmScreenSettings.dmPelsWidth = width; // Selected Screen Width

dmScreenSettings.dmPelsHeight = height; // Selected Screen Height

dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel

dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.

if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.

if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE

}
else
{
// Pop Up A Message Box Letting User Know The Program Is Closing.

MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE; // Return FALSE

}
}
}

if (fullscreen) // Are We Still In Fullscreen Mode?

{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style

dwStyle=WS_POPUP; // Windows Style

ShowCursor(FALSE); // Hide Mouse Pointer

}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style

dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style

}

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size


// Create The Window

if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window

"OpenGL", // Class Name

title, // Window Title

dwStyle | // Defined Window Style

WS_CLIPSIBLINGS | // Required Window Style

WS_CLIPCHILDREN, // Required Window Style

0, 0, // Window Position

WindowRect.right-WindowRect.left, // Calculate Window Width

WindowRect.bottom-WindowRect.top, // Calculate Window Height

NULL, // No Parent Window

NULL, // No Menu

hInstance, // Instance

NULL))) // Dont Pass Anything To WM_CREATE

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be

{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor

1, // Version Number

PFD_DRAW_TO_WINDOW | // Format Must Support Window

PFD_SUPPORT_OPENGL | // Format Must Support OpenGL

PFD_DOUBLEBUFFER, // Must Support Double Buffering

PFD_TYPE_RGBA, // Request An RGBA Format

bits, // Select Our Color Depth

0, 0, 0, 0, 0, 0, // Color Bits Ignored

0, // No Alpha Buffer

0, // Shift Bit Ignored

0, // No Accumulation Buffer

0, 0, 0, 0, // Accumulation Bits Ignored

16, // 16Bit Z-Buffer (Depth Buffer)

0, // No Stencil Buffer

0, // No Auxiliary Buffer

PFD_MAIN_PLANE, // Main Drawing Layer

0, // Reserved

0, 0, 0 // Layer Masks Ignored

};

if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Can''t Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Can''t Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Can''t Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Can''t Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Can''t Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

ShowWindow(hWnd,SW_SHOW); // Show The Window

SetForegroundWindow(hWnd); // Slightly Higher Priority

SetFocus(hWnd); // Sets Keyboard Focus To The Window

ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen


if (!InitGL()) // Initialize Our Newly Created GL Window

{
KillGLWindow(); // Reset The Display

MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE

}

return TRUE; // Success

}

LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window

UINT uMsg, // Message For This Window

WPARAM wParam, // Additional Message Information

LPARAM lParam) // Additional Message Information

{
switch (uMsg) // Check For Windows Messages

{
case WM_ACTIVATE: // Watch For Window Activate Message

{
if (!HIWORD(wParam)) // Check Minimization State

{
active=TRUE; // Program Is Active

}
else
{
active=FALSE; // Program Is No Longer Active

}

return 0; // Return To The Message Loop

}

case WM_SYSCOMMAND: // Intercept System Commands

{
switch (wParam) // Check System Calls

{
case SC_SCREENSAVE: // Screensaver Trying To Start?

case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?

return 0; // Prevent From Happening

}
break; // Exit

}

case WM_CLOSE: // Did We Receive A Close Message?

{
PostQuitMessage(0); // Send A Quit Message

return 0; // Jump Back

}

case WM_KEYDOWN: // Is A Key Being Held Down?

{
keys[wParam] = TRUE; // If So, Mark It As TRUE

return 0; // Jump Back

}

case WM_KEYUP: // Has A Key Been Released?

{
keys[wParam] = FALSE; // If So, Mark It As FALSE

return 0; // Jump Back

}

case WM_SIZE: // Resize The OpenGL Window

{
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height

return 0; // Jump Back

}
}

// Pass All Unhandled Messages To DefWindowProc

return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain( HINSTANCE hInstance, // Instance

HINSTANCE hPrevInstance, // Previous Instance

LPSTR lpCmdLine, // Command Line Parameters

int nCmdShow) // Window Show State

{
MSG msg; // Windows Message Structure

BOOL done=FALSE; // Bool Variable To Exit Loop


// Ask The User Which Screen Mode They Prefer

// if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)

// {

// fullscreen=FALSE; // Windowed Mode

// }

fullscreen = false;
// Create Our OpenGL Window




if (!CreateGLWindow("OpenGL Testing",800,600,32,fullscreen))
{
return 0; // Quit If Window Was Not Created

}

while(!done) // Loop That Runs While done=FALSE

{

if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?

{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?

{
done=TRUE; // If So done=TRUE

}
else // If Not, Deal With Window Messages

{
TranslateMessage(&msg); // Translate The Message

DispatchMessage(&msg); // Dispatch The Message

}
}
else // If There Are No Messages

{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()

if ((active && !DrawGLScene()) || keys[VK_ESCAPE] || keys[''E'']) // Active? Was There A Quit Received?

{
done=TRUE; // ESC or DrawGLScene Signalled A Quit

}
else // Not Time To Quit, Update Screen

{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)

}

if (keys[''F'']) // Is F1 Being Pressed?

{
keys[''F'']=FALSE; // If So Make Key FALSE

KillGLWindow(); // Kill Our Current Window

fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode

// Recreate Our OpenGL Window

if (!CreateGLWindow("NeHe''s Rotation Tutorial",800,600,32,fullscreen))
{
return 0; // Quit If Window Was Not Created

}
}
}
}

// Shutdown

KillGLWindow(); // Kill The Window

return (msg.wParam); // Exit The Program

}


http://www.WoodmanStudios.tk

Share this post


Link to post
Share on other sites
why do you load the texture 3 times?

you''ve got two times the same call to
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
in your code plus a call to gluBuild2DMipmaps. this one internally calls glTexImage2D a couple of times itself so you have an overkill.
so do call either only glTexImage2D once or gluBuild2DMipmaps.

Share this post


Link to post
Share on other sites
ok. I only have one call for that.
i''ve pin-pointed my problem, and the problem is that alpha_bitmap doesn''t contain anything, which means the transfer of data between data to alpha_bitmap(which filters out the pink in the process) fails. help!

Share this post


Link to post
Share on other sites
i won`t go into details but i list here in pseudo code what i did to get it working.

struct rgba{
byte a, r, g, b
}
alpha_bitmap:
load_data_from_bitmap // whatever source
alloc_memory ( size = width*height*sizeof (rgba) )
loop y
loop x
if pixel (x,y) == alpha_color then
write_pixel (255, 255, 255, 0) // 0=alpha
else
write_pixel (r, g, b, 255) // rgb from pixel(x,y)
done
done
glTexImage2D (...)
done

i hope this helps. use a structure like rgba and then just consider the memory like a 2d-array of those structure elements.

Share this post


Link to post
Share on other sites