Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bitmap Displaying Problem

Started by Winegums Dec 21, 2005 at 7:41 AM 8 replies 1.8k views
Original Post
Winegums
Winegums
Hi, first post. Sorry if this is a topic that appears day in, day out but i couldnt see anything about it in the first few pages. I've tried implimenting lesson 6 (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06) into some existing code i have, but the structure is so different in my code and the code used in the example that it doesnt seem to work. I've put in error checking to ensure the image loads and used the default image to minimise problems but still no dice...i think its my draw function thats the problem. With that in mind.... void DrawScene() { int i=0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity();// load Identity Matrix glPushMatrix(); //set camera looking down the -z axis, 10 units away from the center gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0); //Where we are, What we look at, and which way is up glPushMatrix(); glRotated(rot, 1 ,0 ,0); glRotatef(rot, 0 ,1 ,0); glLightfv(GL_LIGHT1, GL_AMBIENT, Light_Ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, Light_Diffuse); glLightfv(GL_LIGHT1, GL_POSITION, Light_Position); glLightfv(GL_LIGHT1, GL_SPECULAR, Light_Specular); glEnable(GL_LIGHT1); glPopMatrix(); glBegin (GL_QUADS); //glMaterialfv(GL_FRONT,GL_EMISSION,mat_emission); //emit blue //front face glNormal3f(0, 0, 1); glVertex3f( -1.0, 1.0, 1.0); glNormal3f(0, 0, 1); glVertex3f( 1.0, 1.0, 1.0); glNormal3f(0, 0, 1); glVertex3f( 1.0, -1.0, 1.0); glNormal3f(0, 0, 1); glVertex3f(-1.0, -1.0, 1.0); //back face glNormal3f(0, 0, -1); glVertex3f( -1.0, 1.0, -1.0); glNormal3f(0, 0, -1); glVertex3f( 1.0, 1.0, -1.0); glNormal3f(0, 0, -1); glVertex3f( 1.0, -1.0, -1.0); glNormal3f(0, 0, -1); glVertex3f(-1.0, -1.0, -1.0); //left face glNormal3f(-1, 0, 0); glVertex3f(-1.0, 1.0, 1.0); glNormal3f(-1, 0, 0); glVertex3f(-1.0, -1.0, 1.0); glNormal3f(-1, 0, 0); glVertex3f( -1.0, -1.0, -1.0); glNormal3f(-1, 0, 0); glVertex3f( -1.0, 1.0, -1.0); //right face glNormal3f(1, 0, 0); glVertex3f(1.0, 1.0, 1.0); glNormal3f(1, 0, 0); glVertex3f(1.0, -1.0, 1.0); glNormal3f(1, 0, 0); glVertex3f(1.0, -1.0, -1.0); glNormal3f(1, 0, 0); glVertex3f(1.0, 1.0, -1.0); //top glNormal3f(0, 1, 0); glVertex3f(-1.0, 1.0, 1.0); glNormal3f(0, 1, 0); glVertex3f(1.0, 1.0, 1.0); glNormal3f(0, 1, 0); glVertex3f(1.0, 1.0, -1.0); glNormal3f(0, 1, 0); glVertex3f(-1.0, 1.0, -1.0); //bottom glNormal3f(0, -1, 0); glVertex3f(-1.0, -1.0, 1.0); glNormal3f(0, -1, 0); glVertex3f(1.0, -1.0, 1.0); glNormal3f(0, -1, 0); glVertex3f(1.0, -1.0, -1.0); glNormal3f(0, -1, 0); glVertex3f(-1.0, -1.0, -1.0); glEnd();//end drawing glPopMatrix(); rot+=0.25; SwapBuffers(ghdc);// Swap the frame buffers. glFlush(); } NB the origonal code had a box with light rotating around it...there were other primatives in there but they were removed 'just in case'...also they made the code snip even longer
Winegums
Winegums
ugh..that was silly...posted wrong version of the code >.<


void DrawScene()
{
int i=0;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen And The Depth Buffer
glLoadIdentity();// load Identity Matrix

//set camera looking down the -z axis, 6 units away from the center
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0); //Where we are, What we look at, and which way is up


// glScalef(sx, sy, sz);
glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis
glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis
glRotatef(zrot,0.0f,0.0f,1.0f); // Rotate On The Z Axis


glRotatef(rot, 0 ,1 ,0);


glLightfv(GL_LIGHT1, GL_AMBIENT, Light_Ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, Light_Diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, Light_Position);
glLightfv(GL_LIGHT1, GL_SPECULAR, Light_Specular);
glEnable(GL_LIGHT1);

glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture

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

xrot+=0.3f;
yrot+=0.2f;
zrot+=0.4f;

SwapBuffers(ghdc);// Swap the frame buffers.

}
Nit
Nit
You need to call glEnable(GL_TEXTURE_2D); before your glBegin() and call glDisable(GL_TEXTURE_2D) after glEnd
Winegums
Winegums
still nothing..was calling it in an initialisation function before...is there a way to check if its active or not?
eSCHEn
eSCHEn
First of all, let's clarify some stuff:
  • Can you see your objects at all?
  • If your objects are visible are they textured properly but dull?
  • Is the texure not visible or seems smudged?
Try removing all calls to lights and their enabling funtions, i.e. remove all glLight* calls and any glEnable(GL_LIGHTING) or glEnable(GL_LIGHT*) calls. This will help to rule out lighting as a problem.

I would test whether you can actually see the object without texturing, so disable texturing as Nit has shown and set the colour to pure white using glColor3ub(255, 255, 255).

If you can see the object but the texturing is smeared or smudged then your texture co-ordinates are incorrect. If you can't see the texture at all then check that it is actually being loaded, remember that MSVC temporarily changes where the executable is being called from when you run from inside the IDE.

Failing that then post your initialization, texture loading and rendering code. Please use source boxes as long pieces of code and infuriating otherwise. [smile] Source boxes are done by surrounding the code with {source}CODE IN HERE{/source} tags. Replace the curly brackets with square ones.

Best of luck!
--
Cheers,
Darren Clark
Winegums
Winegums
sorry, didnt see a code button so assumed there was no such feature :x

the 3d box renders fine, as though there was no call for texturing period. removing lighting just gives me a plain white box. heres the code in its entirety:

//Windows Example Code//Matthew Bett 2005//Shazam!#include <windows.h>#include <stdio.h>#include <mmsystem.h>#include <math.h>#include <gl/gl.h>#include <gl/glu.h>#include <gl/glaux.h>#define COLOUR_DEPTH 16	//Colour depthtypedef struct Mouse{	int x,y;}Mouse;//rotation 'rate'float rot= 0.0;//scale in xyzfloat sx = 1.0;float sy = 1.0;float sz = 1.0;GLfloat		xrot;								// X Rotation GLfloat		yrot;								// Y Rotation GLfloat		zrot;								// Z Rotation GLuint		texture[1];							// Storage For One Texture (change number for more textures)GLfloat Light_Ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};  //RGBA of ambient lightGLfloat Light_Diffuse[] = {6.0f, 6.0f, 6.0f, 1.0f};  //RGBA of light scattered after impactGLfloat Light_Position[]= {-3.0f, 0.0f, 1.5f, 1.0f};  //Position of light sourceGLfloat Light_Specular[]= {0.0f, 0.0f, 1.0f, 1.0f};  //RGBA of bounced beamGLfloat no_shininess[]={0.5};  //makes object completley unreflectiveGLfloat mat_emission[]={0.0,0.3,0.8,0.0}; //RGBA 'emitted' by ojbectHWND        ghwnd;HDC			ghdc;HGLRC		ghrc;			//hardware RENDERING CONTEXTHINSTANCE	ghInstance;RECT		gRect;RECT		screenRect;int S_WIDTH	 =	800;		//client area resolutionint S_HEIGHT =	600;bool		keys[256];Mouse MousePos;LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);void DrawScene();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 Existsif (File)								// Does The File Exist?	{		fclose(File);							// Close The Handle		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer	}	return NULL;								// If Load Failed Return NULL}int LoadGLTextures()									// Load Bitmaps And Convert To Textures{	int Status=FALSE;									// Status Indicator	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit	if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))	{		Status=TRUE;									// Set The Status To TRUE		glGenTextures(1, &texture[0]);					// Create The Texture		// Typical Texture Generation Using Data From The Bitmap		glBindTexture(GL_TEXTURE_2D, texture[0]);		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	}	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 The Image Structure			if(Status==FALSE)		{			MessageBox (NULL, "Bitmap failed to load!",  "Oh Noes!", MB_OK); // error check		}	}	return Status;								// Return The Status}void ResizeGLWindow(int width, int height)// Initialize The GL Window{	if (height==0)// Prevent A Divide By Zero error	{		height=1;// Make the Height Equal One	}	glViewport(0,0,width,height);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	//calculate aspect ratio	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 1 ,150.0f);	glMatrixMode(GL_MODELVIEW);// Select The Modelview Matrix	glLoadIdentity();// Reset The Modelview Matrix}HWND CreateOurWindow(LPSTR strWindowName, int width, int height, DWORD dwstyle, bool bFullScreen, HINSTANCE hInstance){	HWND hwnd;	WNDCLASS wcex;	memset(&wcex, 0, sizeof(WNDCLASS));	wcex.style			= CS_HREDRAW | CS_VREDRAW;			wcex.lpfnWndProc	= WndProc;			wcex.hInstance		= hInstance;							wcex.hIcon			= LoadIcon(NULL, IDI_APPLICATION);; 	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);			wcex.hbrBackground	= (HBRUSH) (COLOR_WINDOW+1);	wcex.lpszMenuName	= NULL;		wcex.lpszClassName	= "FirstWindowClass";			RegisterClass(&wcex);// Register the class	dwstyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;	ghInstance	= hInstance;// Assign our global hInstance to the window's hInstance	//Set the Client area of the window to be our resolution.	RECT glwindow;	glwindow.left		= 0;			glwindow.right		= width;		glwindow.top		= 0;			glwindow.bottom		= height;		AdjustWindowRect( &glwindow, dwstyle, false);	//Create the window	hwnd = CreateWindow(	"FirstWindowClass", 							strWindowName, 							dwstyle, 							0, 							0,							glwindow.right  - glwindow.left,							glwindow.bottom - glwindow.top, 							NULL,							NULL,							hInstance,							NULL							);	if(!hwnd) return NULL;// If we could get a handle, return NULL	ShowWindow(hwnd, SW_SHOWNORMAL);		UpdateWindow(hwnd);						SetFocus(hwnd);							return hwnd;}bool SetPixelFormat(HDC hdc) {     PIXELFORMATDESCRIPTOR pfd = {0};     int pixelformat;      pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);	// Set the size of the structure    pfd.nVersion = 1;							// Always set this to 1	// Pass in the appropriate OpenGL flags    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;     pfd.dwLayerMask = PFD_MAIN_PLANE;			// standard mask (this is ignored anyway)    pfd.iPixelType = PFD_TYPE_RGBA;				// RGB and Alpha pixel type    pfd.cColorBits = COLOUR_DEPTH;				// Here we use our #define for the color bits    pfd.cDepthBits = COLOUR_DEPTH;				// Ignored for RBA    pfd.cAccumBits = 0;							// nothing for accumulation    pfd.cStencilBits = 0;						// nothing for stencil 	//Gets a best match on the pixel format as passed in from device    if ( (pixelformat = ChoosePixelFormat(hdc, &pfd)) == false )     {         MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);         return false;     }  	//sets the pixel format if its ok.     if (SetPixelFormat(hdc, pixelformat, &pfd) == false)     {         MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);         return false;     }      return true;}int InitializeOpenGL(int width, int height) {      ghdc = GetDC(ghwnd);//  sets  global HDC    if (!SetPixelFormat(ghdc))//  sets  pixel format        PostQuitMessage (0);	if (!LoadGLTextures())							// Jump To Texture Loading Routine ( NEW )	{		return FALSE;							// If Texture Didn't Load Return FALSE ( NEW )	}    ghrc = wglCreateContext(ghdc);	//  creates  rendering context from  hdc    wglMakeCurrent(ghdc, ghrc);		//	Use this HRC.	ResizeGLWindow(width, height);	// Setup the Screen}void Init(HWND hwnd){	ghwnd = hwnd;	GetClientRect(ghwnd, &gRect);	//get rect into our handy global rect	InitializeOpenGL(gRect.right, gRect.bottom);// initialise openGL	//OpenGL settings	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	////IMPORTANT		glEnable(GL_LIGHTING); 	//ENABLES LIGHTING		//Also, do any other setting ov variables here for your app if you wish. } void DrawScene() {		int i=0;	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen And The Depth Buffer	glLoadIdentity();// load Identity Matrix	//set camera looking down the -z axis,  6 units away from the center	gluLookAt(0, 0, 10,     0, 0, 0,     0, 1, 0); //Where we are, What we look at, and which way is up	//	glScalef(sx, sy, sz);	glRotatef(xrot,1.0f,0.0f,0.0f);						// Rotate On The X Axis	glRotatef(yrot,0.0f,1.0f,0.0f);						// Rotate On The Y Axis	glRotatef(zrot,0.0f,0.0f,1.0f);						// Rotate On The Z Axis//	glTranslatef( 0.0, 1.0, 0.0 );	glRotatef(rot, 0 ,1 ,0);	glLightfv(GL_LIGHT1, GL_AMBIENT,  Light_Ambient);	glLightfv(GL_LIGHT1, GL_DIFFUSE,  Light_Diffuse);	glLightfv(GL_LIGHT1, GL_POSITION, Light_Position);	glLightfv(GL_LIGHT1, GL_SPECULAR, Light_Specular);	glEnable(GL_LIGHT1);	glBindTexture(GL_TEXTURE_2D, texture[0]);				// Select Our Texture	glEnable(GL_TEXTURE_2D);						// Enable Texture Mapping	glBegin(GL_QUADS);		// Front Face		glNormal3f(0, 0, 1);		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad		glNormal3f(0, 0, 1);		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		glNormal3f(0, 0, 1);		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad		glNormal3f(0, 0, 1);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad		// Back Face		glNormal3f(0, 0, -1);		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad		glNormal3f(0, 0, -1);		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad		glNormal3f(0, 0, -1);		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad		glNormal3f(0, 0, -1);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad		// Top Face		glNormal3f(0, 1, 0);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad		glNormal3f(0, 1, 0);		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad		glNormal3f(0, 1, 0);		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		glNormal3f(0, 1, 0);		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad		// Bottom Face		glNormal3f(0, -1, 0);		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad		glNormal3f(0, -1, 0);		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad		glNormal3f(0, -1, 0);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad		glNormal3f(0, -1, 0);		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		// Right face		glNormal3f(1, 0, 0);		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad		glNormal3f(1, 0, 0);		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad		glNormal3f(1, 0, 0);		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad		glNormal3f(1, 0, 0);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad		// Left Face		glNormal3f(-1, 0, 0);		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad		glNormal3f(-1, 0, 0);		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		glNormal3f(-1, 0, 0);		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad		glNormal3f(-1, 0, 0);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad	glEnd();	glDisable(GL_TEXTURE_2D);						// Disable Texture Mapping	xrot+=0.3f;								// X Axis Rotation	yrot+=0.2f;								// Y Axis Rotation	zrot+=0.4f;								// Z Axis Rotation	SwapBuffers(ghdc);// Swap the frame buffers.}void Cleanup(){	if (ghrc)	{		wglMakeCurrent(NULL, NULL);	// free rendering memory		wglDeleteContext(ghrc);		// Delete our OpenGL Rendering Context	}	if (ghdc) 	ReleaseDC(ghwnd, ghdc);			// Release our HDC from memory	UnregisterClass("FirstWindowClass", ghInstance);// Free the window class	PostQuitMessage (0);		// Post a QUIT message to the window}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){    switch (message)											    {																case WM_CREATE:				break;		case WM_SIZE:			//resize the open gl window when the window is resized			ResizeGLWindow(LOWORD(lParam),HIWORD(lParam));			GetClientRect(hwnd, &gRect);			break;			case WM_KEYDOWN:		       switch (wParam)             { 				case VK_SPACE:                    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);                    break; 					case VK_RETURN:                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);					break;            	case 'A':					rot+=1.0;                    break;				case 'D':					rot-=1.0;					break;				case 'Q':					PostQuitMessage(0);						break;				case 'T':					sx+=0.15;					break;				case 'G':					sx-=0.15;					break;				case 'Y':					sy+=0.15;					break;				case 'H':					sy-=0.15;					break;				case 'U':					sz+=0.15;					break;				case 'J':					sz-=0.15;					break;			}		case WM_KEYUP:			keys[wParam]=false;			break;		case WM_MOUSEMOVE:			MousePos.x = LOWORD (lParam);			MousePos.y = HIWORD (lParam);			break;		case WM_PAINT:						    break;				case WM_DESTROY:							PostQuitMessage(0);												break;					}														return DefWindowProc (hwnd, message, wParam, lParam);																	}int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,                    PSTR szCmdLine, int nCmdShow)			{		HWND		hwnd;    MSG         msg;		//initialise and create window	hwnd = CreateOurWindow("SuperDuper Opengl APP", S_WIDTH, S_HEIGHT, 0, false, hInstance);		if(hwnd == NULL) return true;	//initialise opengl and other settings	Init(hwnd);		while (true)					    {									if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))		{		    if (msg.message==WM_QUIT)				break;			TranslateMessage (&msg);										DispatchMessage (&msg);		}		else		{					//any intensive proccessing for the app,  do it here. 			DrawScene();		}    }	return msg.wParam ;										}
eSCHEn
eSCHEn
Ok, I see you have sorted out the source box, good [smile]. Your problem is that you are trying to load textures before you have created a valid rendering context (RC). To fix this, go to your 'InitializeOpenGL' function and change it to this:
int InitializeOpenGL(int width, int height) {      ghdc = GetDC(ghwnd);//  sets  global HDC    if (!SetPixelFormat(ghdc))//  sets  pixel format        PostQuitMessage (0);    ghrc = wglCreateContext(ghdc);	//  creates  rendering context from  hdc    wglMakeCurrent(ghdc, ghrc);		//	Use this HRC.	ResizeGLWindow(width, height);	// Setup the Screen	if (!LoadGLTextures())							// Jump To Texture Loading Routine ( NEW )	{		return false;							// If Texture Didn't Load Return FALSE ( NEW )	}	return true;}
Also, you will need to comment out the line "glEnable(GL_LIGHTING);" in your "Init" function as well.

This will fix your problems. Have fun!
--
Cheers,
Darren Clark
Winegums
Winegums
what an annoying mistake to make -.-

thanks a lot for the help
eSCHEn
eSCHEn
Not a problem mate, we all have to start somewhere. Welcome to NeHe and GameDev, have fun and get coding!
--
Cheers,
Darren Clark

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.