Archived

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

Deranged

Undesired Affect

Recommended Posts

Before MD2 Loading Undesired Affect MD2 CODE
int InitGL(GLvoid)										// All Setup For OpenGL Goes Here

{       

   	g_FontListID = CreateOpenGLFont("Arial", FONT_HEIGHT);
	

	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading

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

	glClearDepth(1.0f);	
 	g_Camera.PositionCamera(0, 1.5f, 6,   0, 1.5f, 0,   0, 1, 0);						
		glDisable(GL_DEPTH_TEST);
 	glDisable(GL_CULL_FACE);
  	glDisable(GL_TEXTURE_2D);					

 	glDisable(GL_TEXTURE_2D);
   
    
          
    	g_LoadMd2.ImportMD2(&g_3DModel, FILE_NAME, TEXTURE_NAME);		
         
	// Go through all the materials

	for(int i = 0; i < g_3DModel.numOfMaterials; i++)
	{
		// Check to see if there is a file name to load in this material

		if(strlen(g_3DModel.pMaterials[i].strFile) > 0)
		{
			// Use the name of the texture file to load the bitmap, with a texture ID (i).

			// We pass in our global texture array, the name of the texture, and an ID to reference it.	

			CreateTexture2(g_Texture2, g_3DModel.pMaterials[i].strFile, i);			
		}

		// Set the texture ID for this material

		g_3DModel.pMaterials[i].texureId = i;
	}
          
	glEnable(GL_DEPTH_TEST);
 	glEnable(GL_CULL_FACE);
  	glEnable(GL_TEXTURE_2D);					
	glCullFace(GL_FRONT);
 	glEnable(GL_TEXTURE_2D);
    glDepthFunc(GL_LEQUAL);	              							// The Type Of Depth Testing To Do

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

	return TRUE;										// Initialization Went OK

}

Side Bar Code
   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();
	 glColor3f(1,1,1);
	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix

	glLoadIdentity();									// Reset The Projection Matrix

	glOrtho(0,SCREEN_HEIGHT,0,SCREEN_WIDTH,500,-500);
	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix

	glLoadIdentity();
	glPopMatrix();
	glPushMatrix();
	
	glBegin(GL_QUADS);						// Draw A Quad

	glColor3f(0, 0, 1);glVertex3f( 0.0f, 1024.0f, 0.0f);				// Top Left

	glColor3f(0, 1, 0);glVertex3f( 140.0f, 1024.0f , 0.0f);				// Top Right

	glColor3ub(0, 0, 0);glVertex3f( 110.0f,0.0f , 0.0f);				// Bottom Right

	glColor3ub(0, 0, 0);glVertex3f(0.0f,0.0f, 0.0f);				// Bottom Left

	glEnd();
	
	glBegin(GL_QUADS);						// Draw A Quad

        glColor3ub(0, 0, 0);
    	glVertex3f( 10.0f, 970.0f, 0.0f);				// Top Left

	    glVertex3f( 130.0f, 970.0f , 0.0f);				// Top Right

		glVertex3f( 130.0f,940.0f , 0.0f);				// Bottom Right

		glVertex3f(10.0f,940.0f, 0.0f);				// Bottom Left

	glEnd();
	glBegin(GL_QUADS);						// Draw A Quad

        glColor3ub(0, 0, 0);
    	glVertex3f( 10.0f, 920.0f, 0.0f);				// Top Left

	    glVertex3f( 130.0f, 920.0f , 0.0f);				// Top Right

		glVertex3f( 130.0f,890.0f , 0.0f);				// Bottom Right

		glVertex3f(10.0f,890.0f, 0.0f);				// Bottom Left

	glEnd();
		glBegin(GL_QUADS);						// Draw A Quad

        glColor3f(0, 0, 1);
    	glVertex3f( 20.0f, 965.0f, 0.0f);				// Top Left

	    glVertex3f( hpbar, 965.0f , 0.0f);				// Top Right

		glVertex3f( hpbar,945.0f , 0.0f);				// Bottom Right

		glVertex3f(20.0f,945.0f, 0.0f);				// Bottom Left

	glEnd();
			glBegin(GL_QUADS);						// Draw A Quad

        glColor3f(0, 0, 1);
    	glVertex3f( 20.0f, 915.0f, 0.0f);				// Top Left

	    glVertex3f( mpbar, 915.0f , 0.0f);				// Top Right

		glVertex3f( mpbar,895.0f , 0.0f);				// Bottom Right

		glVertex3f(20.0f,895.0f, 0.0f);				// Bottom Left

	glEnd();
	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix

	glLoadIdentity();									// Reset The Projection Matrix

	gluPerspective(45.0f,(GLfloat)SCREEN_WIDTH/(GLfloat)SCREEN_HEIGHT,0.1f,100.0f);
	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix

	glLoadIdentity();
	glPopMatrix();
	glPushMatrix();
    g_Camera.Look();
    glColor3f(1,1,1);		
	glDrawText(60, 38 , "HP: %d / %d", hp, Maxhp);	
	glDrawText(60, 77 , "MP: %d / %d", mp, Maxmp);		
	g_bar();


	
   AnimateMD2Model(&g_3DModel);
   glColor3f(1,1,1);
       
         			
    Draw3DSGrid();
    SwapBuffers(hDC);
	return TRUE;										// Everything Went OK

}
Im using the MD2 Anim code from GameTutorials.com. [edited by - DerAngeD on January 5, 2004 8:55:36 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by cowsarenotevil
Um, what's the undesired effect?




Please look at those 2 links. First the before than the Effect.

EDIT: If you cant tell the effect is the grid and the side bar turns black after i load the MD2.


[edited by - DerAngeD on January 5, 2004 9:01:39 PM]

Share this post


Link to post
Share on other sites
Uhm, your code probably either moves the camera away from your original stuff, or overwrites it since the loading code is after the other code.

Share this post


Link to post
Share on other sites
its not overwriting things because i moved the loadeing code around and it was the same. Its not moving the camera because ive tried rendering it before the camera.

Share this post


Link to post
Share on other sites
quote:
Original post by pinacolada
Maybe it''s that a big monster comes and takes over his desktop!


That''s what I would have though ...

Being serious though, it looks like you''re setting up your projections wrong. Try it like this:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//--Width then height

glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1, 1);
//--Might also be:

//glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1);

//--Or... (I usually have to play with the orthographic

//--projection for it to work right...)

//glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//

//--Render 2D Data

//

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
//

//--Render 3D Data

//



Also, I would render the 3D grid then the model. If not you''re going to have render order problems (The grid will look like it''s going through the model)

Also, whats g_bar();? Is that the frame on the left side? If it is, why are you rendering it in the perspective projection area instead of the orthographic projection?

Also, when rendering your quake model, does it reverse the winding order of the vertices? If it does and you have glCullFace(GL_FRONT);, then it could be culling the 2D data?

Also, did you try taking out glDepthFunc(GL_LEQUAL); as that might be doing it? Just comment it out once and see what it does...

Theres a lot of things that it could be. It''s hard to fix it without actually playing with it.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
commenting out glDepthFunc(GL_LEQUAL); doesnt help and g_bar(); is the calcuations for how much hp/mp is left in the health/mp bar.

Share this post


Link to post
Share on other sites
Well here is what I was mostly concerned about:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(1,1,1);
glMatrixMode(GL_PROJECTION);
glOrtho(0,SCREEN_HEIGHT,0,SCREEN_WIDTH,500,-500);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPopMatrix();
glPushMatrix();

If I''m thinking right, your popping the modelview matrix. Usually when you don''t want the matrices messed with, you push a new matrix, do whatever you have to do, and then pop it. I''ve never seen it where you pop a matrix after setting the modelview. Take out the pushing and popping and see what happens...

Share this post


Link to post
Share on other sites
That''s in your initialize code, you''re not rendering anything yet... If you comment out AnimateMD2Model(&g_3DModel);, is that when your 2D stuff gets rendered? What do you do to get your 2D stuff to render?

Obviously it was rendering before, so What did you add that made it go away? Because whatever you''re rendering now needs looked at. It''s probably in the AnimateMD2Model(&g_3DModel); function.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
quote:
Original post by UltimaX
That's in your initialize code, you're not rendering anything yet... If you comment out AnimateMD2Model(&g_3DModel);, is that when your 2D stuff gets rendered? What do you do to get your 2D stuff to render?

Obviously it was rendering before, so What did you add that made it go away? Because whatever you're rendering now needs looked at. It's probably in the AnimateMD2Model(&g_3DModel); function.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Ive tried that its in the init code. Ive gone through MD2.h and MD2.cpp and i cant find the problem.


[edited by - DerAngeD on January 5, 2004 9:45:21 PM]

Share this post


Link to post
Share on other sites
Hmmm...
Instead of:
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);

//--Import MD2/Load Textures

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

Try:
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

//--Import MD2/Load Textures



If it's in the initialize code, then a state is getting set that shouldn't be. See what states are being set in the g_LoadMd2.ImportMD2(*) function.

P.S. Didn't I tell you it would be hard to tell without playing with it We'll figure it out sooner or later lol. There's always a solution, don't you love programming! Logics fun!

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on January 5, 2004 9:53:29 PM]

Share this post


Link to post
Share on other sites
now ive narrowed it down again to this bitmap loading code.

bool CreateTexture2(UINT textureArray[], LPSTR strFileName, int textureID)					
{
HBITMAP hBMP;
BITMAP BMP;

glGenTextures(1, &textureArray[textureID]);
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), strFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );

if (!hBMP)
return FALSE;

GetObject(hBMP, sizeof(BMP), &BMP);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

DeleteObject(hBMP);

return TRUE;
}

Share this post


Link to post
Share on other sites
Try using:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

Instead of:
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
quote:
Original post by UltimaX
Try using:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

Instead of:
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"



nope it wont work either.

Heres how i use the loading code.
    	for(int i = 0; i < g_3DModel.numOfMaterials; i++)
{
// Check to see if there is a file name to load in this material

if(strlen(g_3DModel.pMaterials[i].strFile) > 0)
{
// Use the name of the texture file to load the bitmap, with a texture ID (i).


CreateTexture2(g_Texture2, g_3DModel.pMaterials[i].strFile, i);

}

// Set the texture ID for this material

g_3DModel.pMaterials[i].texureId = i;
}

Share this post


Link to post
Share on other sites
I'm confused... Even if the texture ID's were wrong (I.E. Reassigned by the MD2 texture ID's) it should still show up with the overwritten textures. If no textures were present, you would just get colored polygons. You're not seeing anyone of those situations. I still think it's in your rendering or setting of the states somewhere.

If you don't mind, send me the code and I will fix it for you. It has become personal. (Don't worry, If I wanted an MD2 loader I could get one) My e-mail is arielproductions@zoominternet.net

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on January 5, 2004 10:26:26 PM]

Share this post


Link to post
Share on other sites
The textures render fine but when they render everything else turns black.

[edited by - DerAngeD on January 5, 2004 10:29:28 PM]

Share this post


Link to post
Share on other sites
Then it''s not your texture loader. It''s in the rendering/states like I said before.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
it has to be the load because if i comment out CreateTexture2(g_Texture2, g_3DModel.pMaterials.strFile, i); the texture wont load but i can see the grid and side bar.

Share this post


Link to post
Share on other sites
o and its the same if i try CreateTexture2(g_Texture2, "hobgoblin.bmp", 0); so does anyone have better bitmap loading code(besides nehes glaux replacement)

Share this post


Link to post
Share on other sites
If it's showing up when you comment that out, then try this bitmap loader and see what happens:

The Texture Definition:

struct TEXTURE
{
int Width;
int Height;
int Channels;
unsigned char *Data;
unsigned int TextureID;
};


Bitmap Loader:

inline TEXTURE* LoadBMP(char* Filename, BITMAPINFOHEADER *HeaderInfo)
{
TEXTURE *Texture = NULL;
BITMAPFILEHEADER Header;
unsigned char Pixel;
FILE *File = NULL;
//

File = fopen(Filename, "rb");
if(File == NULL)
{
char BUFFER[256];
sprintf(BUFFER, "Unable to load the texture: %s", Filename);
MessageBox(NULL, BUFFER, "[ERROR]", MB_OK);
return NULL;
}
//

fread(&Header, sizeof(BITMAPFILEHEADER), 1, File);
if(Header.bfType != 0x4D42)
{
fclose(File);
return NULL;
}
//

Texture = new TEXTURE;
if(Texture == NULL)
{
fclose(File);
return NULL;
}
//

fread(HeaderInfo, sizeof(BITMAPINFOHEADER), 1, File);
fseek(File, Header.bfOffBits, SEEK_SET);
//

Texture->Data = new unsigned char[HeaderInfo->biSizeImage * 3];
if(!Texture->Data)
{
if(Texture)
{
delete Texture;
Texture = NULL;
}
fclose(File);
return NULL;
}
//

fread(Texture->Data, 1, HeaderInfo->biSizeImage, File);
if(Texture->Data == NULL)
{
if(Texture)
{
delete Texture;
Texture = NULL;
}
fclose(File);
return NULL;
}
//

for(unsigned long PixelID = 0; PixelID < HeaderInfo->biSizeImage; PixelID += 3)
{
Pixel = Texture->Data[PixelID];
Texture->Data[PixelID + 0] = Texture->Data[PixelID + 2];
Texture->Data[PixelID + 2] = Pixel;
}
//

Texture->Channels = 3;
Texture->Width = HeaderInfo->biWidth;
Texture->Height = HeaderInfo->biHeight;
fclose(File);
return Texture;
}


Load/Setup Texture:

TEXTURE& CreateTexture(char* FileName, int TextureID)
{
BITMAPINFOHEADER BHEADER;
TEXTURE *Texture = LoadBMP(FileName, &BHEADER);
if(Texture == NULL)
{
return (TEXTURE&)*Texture;
}
//

Texture->TextureID = TextureID;
glGenTextures(1, &TextureID);
glBindTexture(GL_TEXTURE_2D, TextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, Texture->Channels, Texture->Width, Texture->Height, GL_RGB, GL_UNSIGNED_BYTE, Texture->Data);
}


-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on January 5, 2004 11:04:22 PM]

Share this post


Link to post
Share on other sites
Well crap... Well at least it's fixed
Theres a bitmap loader anyway instead of using GLAUX which is old anyway.

EDIT
BTW, best of luck on your project.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on January 5, 2004 11:02:14 PM]

Share this post


Link to post
Share on other sites