Jump to content
  • Advertisement

Archived

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

Metal Typhoon

Why can't i see the outside ??

This topic is 5904 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

somehow i can''t see the outside of a polygon.. it''s strange.. i draw a simple cube but when it''s rotating i can see the back of the back face... here''s a pic http://www.metaltyphoon.hpg.com.br//argh.jpg .... thx in advance... here''s my only source..
  
//*******************************************

//Pragmas

#pragma comment (lib,"glu32.lib")
#pragma comment (lib,"glaux.lib")
#pragma comment (lib,"opengl32.lib")
//*******************************************

//Includes 

#include <stdio.h>
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
//*******************************************

//Defines

#define SCREEN_WIDTH 600
#define SCREEN_HEIGHT 480
//*******************************************

//Variables 


HDC 	hdc;
HWND	hwnd;
UINT    Texture[1];
HGLRC	hrc;
float	Xrot,Yrot,Zrot;
char Class_Name[] = "Code - Name";
//*******************************************

//Functions

void RenderScene ();
void Enable_Opengl ();
void Disable_Opengl ();
int LoadTexture (char *filename);
AUX_RGBImageRec *LoadBMP (char *filename);
//*******************************************


LRESULT CALLBACK WndProc (HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	switch (msg)
	{
		default:
			return DefWindowProc (hwnd,msg,wparam,lparam);
	}

	return 0;
}

int WINAPI WinMain (HINSTANCE hInstance ,HINSTANCE hPrecInstance,LPSTR lpCmdLine,int nShowCmd)
{
	WNDCLASS wc;
	MSG 	 msg;

	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH) GetStockObject (4);
	wc.hCursor = LoadCursor (NULL,IDC_ARROW);
	wc.hIcon = LoadIcon (NULL,IDI_APPLICATION);
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = Class_Name;
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;

	if (!RegisterClass (&wc))
	{
		MessageBox (NULL,"Error registering the class","Code - Name",MB_OK|MB_ICONEXCLAMATION);
		return 0;
	}

	hwnd = CreateWindow (
			Class_Name,
			"Code - Name",
			WS_CAPTION,0,0,
			SCREEN_WIDTH,SCREEN_HEIGHT
			,NULL,NULL,hInstance,NULL);

	ShowWindow (hwnd,nShowCmd);
	UpdateWindow (hwnd);
	Enable_Opengl ();

	while (1)
	{
		if (PeekMessage (&msg,hwnd,0,0,PM_REMOVE))
		{
			if (msg.wParam == VK_ESCAPE)
			{
				break;
			}
			
			TranslateMessage (&msg);
			DispatchMessage (&msg);
		}
		else
		{
			RenderScene();
		}
	}

	Disable_Opengl();
	return 0;
}

void RenderScene ()
{
	glLoadIdentity();
	glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glRotatef (Xrot,1.0f,0.0f,0.0f);
	glRotatef (Yrot,0.0f,1.0f,0.0f);
	glRotatef (Zrot,0.0f,0.0f,1.0f);

	glBegin (GL_QUADS);
		// Front Face

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f,  0.5f);	// Bottom Left Of The Texture and Quad

		glTexCoord2f(0.5f, 0.0f); glVertex3f( 0.5f, -0.5f,  0.5f);	// Bottom Right Of The Texture and Quad

		glTexCoord2f(0.5f, 0.5f); glVertex3f( 0.5f,  0.5f,  0.5f);	// Top Right Of The Texture and Quad

		glTexCoord2f(0.0f, 0.5f); glVertex3f(-0.5f,  0.5f,  0.5f);	// Top Left Of The Texture and Quad

		// Back Face 

		glTexCoord2f(0.5f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);	// Bottom Right Of The Texture and Quad

		glTexCoord2f(0.5f, 0.5f); glVertex3f(-0.5f,  0.5f, -0.5f);	// Top Right Of The Texture and Quad

		glTexCoord2f(0.0f, 0.5f); glVertex3f( 0.5f,  0.5f, -0.5f);	// Top Left Of The Texture and Quad

		glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f);	// Bottom Left Of The Texture and Quad

		// Top Face

		glTexCoord2f(0.0f, 0.5f); glVertex3f(-0.5f,  0.5f, -0.5f);	// Top Left Of The Texture and Quad

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f,  0.5f,  0.5f);	// Bottom Left Of The Texture and Quad

		glTexCoord2f(0.5f, 0.0f); glVertex3f( 0.5f,  0.5f,  0.5f);	// Bottom Right Of The Texture and Quad

		glTexCoord2f(0.5f, 0.5f); glVertex3f( 0.5f,  0.5f, -0.5f);	// Top Right Of The Texture and Quad

		// Bottom Face

		glTexCoord2f(0.5f, 0.5f); glVertex3f(-0.5f, -0.5f, -0.5f);	// Top Right Of The Texture and Quad

		glTexCoord2f(0.0f, 0.5f); glVertex3f( 0.5f, -0.5f, -0.5f);	// Top Left Of The Texture and Quad

		glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f,  0.5f);	// Bottom Left Of The Texture and Quad

		glTexCoord2f(0.5f, 0.0f); glVertex3f(-0.5f, -0.5f,  0.5f);	// Bottom Right Of The Texture and Quad

		// Right face

		glTexCoord2f(0.5f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f);	// Bottom Right Of The Texture and Quad

		glTexCoord2f(0.5f, 0.5f); glVertex3f( 0.5f,  0.5f, -0.5f);	// Top Right Of The Texture and Quad

		glTexCoord2f(0.0f, 0.5f); glVertex3f( 0.5f,  0.5f,  0.5f);	// Top Left Of The Texture and Quad

		glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f,  0.5f);	// Bottom Left Of The Texture and Quad

		// Left Face

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);	// Bottom Left Of The Texture and Quad

		glTexCoord2f(0.5f, 0.0f); glVertex3f(-0.5f, -0.5f,  0.5f);	// Bottom Right Of The Texture and Quad

		glTexCoord2f(0.5f, 0.5f); glVertex3f(-0.5f,  0.5f,  0.5f);	// Top Right Of The Texture and Quad

		glTexCoord2f(0.0f, 0.5f); glVertex3f(-0.5f,  0.5f, -0.5f);	// Top Left Of The Texture and Quad

	glEnd();
	SwapBuffers (hdc);

	Xrot += 0.3f;
	Yrot += 0.2f;
	Zrot += 0.4f;

}

void Enable_Opengl ()
{
	int Format;
	PIXELFORMATDESCRIPTOR pfd;

	hdc = GetDC (hwnd);
	
	pfd.cDepthBits = 16;
	pfd.cColorBits = 24;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.nSize = sizeof (pfd);
	pfd.nVersion = 1;
	Format = ChoosePixelFormat (hdc,&pfd);
	SetPixelFormat (hdc,Format,&pfd);

	hrc = wglCreateContext (hdc);
	wglMakeCurrent (hdc,hrc);

	glClearDepth (1.0f);
	glEnable (GL_DEPTH_TEST);
	glEnable (GL_TEXTURE_2D);
	glDepthFunc (GL_LEQUAL);

	glHint (GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

	gluPerspective (0.45f,SCREEN_WIDTH / SCREEN_HEIGHT,0.0f,100.0f);
	glLoadIdentity ();

	if (!LoadTexture ("Data/Crate.bmp"))
	{
		MessageBox (NULL,"Error loading texture(s)","Code - Name",MB_OK|MB_ICONEXCLAMATION);
	}

	
}

void Disable_Opengl ()
{
	wglMakeCurrent (NULL,NULL);
	wglDeleteContext (hrc);
	ReleaseDC (hwnd,hdc);
}

int LoadTexture (char *filename)
{
	bool Status = false;

	AUX_RGBImageRec *TextureImage[1];
	memset (Texture,0,sizeof (void *) *1);

	if (TextureImage[0] = LoadBMP (filename))
	{
		Status = true;

		glGenTextures (1,&Texture[0]);
		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 (TextureImage[0]->data)
		{
			free (TextureImage[0]->data);
		}

		free (TextureImage[0]);
	}

	return Status;
}

AUX_RGBImageRec *LoadBMP (char *filename)
{
	if (!filename)
	{
		return 0;
	}

	FILE *File = NULL;
	File =  fopen (filename,"r");

	if (File)
	{
		fclose (File);
		return auxDIBImageLoad (filename);
	}
}

  
Metal Typhoon

Share this post


Link to post
Share on other sites
Advertisement
disabling backface culling should solve your problem

(and please dont post ALL your code )


mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.

Share this post


Link to post
Share on other sites
quote:
Original post by LousyPhreak
disabling backface culling should solve your problem

(and please dont post ALL your code )


mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.


ehehh sorry.. i thought about not posting about alll the coding lol.. sorry... how do i disable that ?? ''m new to ogl

Metal Typhoon

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try this,
at your call to gluPerspective, instead of 0.0f value for the Near parameter, try to put 0.1f.
I had the same problem one day, i don''t know why, but when I changed this parameter i resolved it. I hope I helped you.

guillempalou@hotmail.com

Share this post


Link to post
Share on other sites
Maybe you should try enabling depth testing.Try this:

glEnable(GL_DEPTH_TEST)


The pain is coming...this sommer!!!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!