Advertisement

TEXTURE PROBLEM!!!!!

Started by November 22, 2003 11:08 PM
4 comments, last by dennizzz 21 years, 3 months ago
why isn't this piece of shit working to texture? i just want a simple texture loading... i dump all my code here... i'm sick of it.

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

#include "main.h"										// This includes our header file

#pragma comment (lib, "fmodvc.lib")
#include "fmod.h"
#include <math.h>		
#include <stdio.h>		
#include <stdarg.h>

bool  g_bFullScreen = TRUE;								// Set full screen as default

HWND  g_hWnd;											// This is the handle for the window

RECT  g_rRect;											// This holds the window dimensions

HDC   g_hDC;											// General HDC - (handle to device context)

HGLRC g_hRC;											// General OpenGL_DC - Our Rendering Context for OpenGL

HINSTANCE g_hInstance;									// This holds the global hInstance for UnregisterClass() in DeInit()


GLUquadricObj *quadratic;

GLfloat rakna;
int baj;
GLuint	base;
GLuint	filter;				// Which Filter To Use

GLuint		texture[1];
GLuint  object=1;

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	

GLYPHMETRICSFLOAT gmf[256];

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *



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

{
	FILE *File=NULL;							// File Handle


	File=fopen(Filename,"r");

	if (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


if (TextureImage[0]=LoadBMP("Data/baj.bmp"))
	{
		Status=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);	// Linear Filtering

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering

	}
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

	}
return Status;								// Return The Status

}




void F_CALLBACKAPI scene2(FMUSIC_MODULE *mod, unsigned char param)
{
	baj = 20;
    
}

GLvoid BuildFont(GLvoid)					// Build Our Bitmap Font

{
	HFONT	font;						// Windows Font ID

	HFONT	oldfont;					// Used For Good House Keeping


	base = glGenLists(256);					

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

	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

	"Broken Toys");			// Font Name

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

	wglUseFontOutlines(g_hDC, 0, 256, base, 0.0f, 0.2f, WGL_FONT_POLYGONS, gmf);			// Builds 96 Characters Starting At Character 32

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

	DeleteObject(font);					// Delete The Font

}



GLvoid KillFont(GLvoid)						// Delete The Font List

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

}

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

{

char		text[256];				// Holds Our String

float		length=0;
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

	for (unsigned int loop=0;loop<(strlen(text));loop++)	// Loop To Find Text Length

	{
		length+=gmf[text[loop]].gmfCellIncX;		// Increase Length By Each Characters Width

	}
    glTranslatef(-length/2,0.0f,0.0f);

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

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

	glPopAttrib();						// Pops The Display List Bits	( NEW )

}








///////////////////////////////// INIT GAME WINDOW \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

/////

/////	This function initializes the game window.

/////

///////////////////////////////// INIT GAME WINDOW \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*


void Init(HWND hWnd)
{
	LoadGLTextures();
	g_hWnd = hWnd;										// Assign the window handle to a global window handle

	GetClientRect(g_hWnd, &g_rRect);					// Assign the windows rectangle to a global RECT

	InitializeOpenGL(g_rRect.right, g_rRect.bottom);	// Init OpenGL with the global rect

	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping

	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

	glDepthFunc(GL_LEQUAL);	
	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

    quadratic=gluNewQuadric();							// Create A Pointer To The Quadric Object (Return 0 If No Memory)

	gluQuadricNormals(quadratic, GLU_SMOOTH);			// Create Smooth Normals 

	gluQuadricTexture(quadratic, GL_TRUE);	
	rakna=1.0f;
	baj=1;
	FMUSIC_MODULE *mod = 0;
	FSOUND_Init(44100,32,0);
	mod = FMUSIC_LoadSong("TETT.XM");
	FMUSIC_PlaySong(mod); 
//	FMUSIC_SetInstCallback(mod, scene2, 7);

	glShadeModel(GL_SMOOTH);
	glEnable(GL_LIGHT0);					// Enable Default Light (Quick And Dirty)	( NEW )

	glEnable(GL_LIGHTING);					// Enable Lighting				( NEW )

	glEnable(GL_COLOR_MATERIAL);
	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set The Texture Generation Mode For S To Sphere Mapping (NEW)

	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
	BuildFont();



	// The rest of our initialization would go here (Models, textures, etc...)

}



///////////////////////////////// MAIN GAME LOOP \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

/////

/////	This function Handles the main game loop

/////

///////////////////////////////// MAIN GAME LOOP \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*


WPARAM MainLoop()
{
	MSG msg;

	while(1)											// Do our infinate loop

	{													// Check if there was a message

		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
        { 
			if(msg.message == WM_QUIT)					// If the message wasnt to quit

				break;
            TranslateMessage(&msg);						// Find out what the message does

            DispatchMessage(&msg);						// Execute the message

        }
		else											// If there wasn't a message

		{ 
		   if(baj < 2)
		   {
			RenderScene();								// Reder the scene every frame to reflect animation

		   }
		   
		   if(baj > 15)
		   {
			RenderScene2();
		   }
		   

        } 
	}

	DeInit();											// Clean up and free all allocated memory


	return(msg.wParam);									// Return from the program

}

///////////////////////////////// RENDER SCENE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

/////

/////	This function renders the entire scene.

/////

///////////////////////////////// RENDER SCENE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*


float rotX = 0.0f, rotZ = 0.0, rotY = 0.0f;

void RenderScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer

	glLoadIdentity();	
	
	glPushMatrix();
	
	glTranslatef(0.0f,0.0f,-8.0f);
	glEnable(GL_TEXTURE_GEN_S);							// Enable Texture Coord Generation For S (NEW)

	glEnable(GL_TEXTURE_GEN_T);	
	
	glRotatef(rotX,1,1,1);
//	glColor3ub(255,255,255);

	glBindTexture(GL_TEXTURE_2D, texture[filter+(filter+1)]);
	gluCylinder(quadratic,1.0f,1.0f,3.0f,32,32);

	glPopMatrix();

	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);

		// This Will Select The BG Maps...

	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTranslatef(0.0f, 0.0f, -60.0f);
		glBegin(GL_QUADS);
			glNormal3f( 0.0f, 0.0f, 1.0f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-13.3f, -10.0f,  10.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( 13.3f, -10.0f,  10.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( 13.3f,  10.0f,  10.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-13.3f,  10.0f,  10.0f);
		glEnd();
	glPopMatrix();



	rotX += 0.3f;										// Increase the X rotation

	rotY += 0.3f;										// Increase the Y rotation

	rotZ += 0.8f;										// Increase the Z rotation


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


	SwapBuffers(g_hDC);									// Swap the backbuffer to the foreground

}

void RenderScene2() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer

	glLoadIdentity();
	gluLookAt(0, 0, 6,     0, 0, 0,     0, 1, 0);

	glRotatef(rotX,1.0f,1.0f,1.0f);
	glEnable(GL_BLEND);	
	glBlendFunc(GL_ONE, GL_ONE);
	glBegin(GL_QUADS);									// Draw A Quad

		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Green

		glVertex3f( 1.0f, 1.0f,-1.0f);					// Top Right Of The Quad (Top)

		glVertex3f(-1.0f, 1.0f,-1.0f);					// Top Left Of The Quad (Top)

		glVertex3f(-1.0f, 1.0f, 1.0f);					// Bottom Left Of The Quad (Top)

		glVertex3f( 1.0f, 1.0f, 1.0f);					// Bottom Right Of The Quad (Top)

		glColor3f(1.0f,0.5f,0.0f);						// Set The Color To Orange

		glVertex3f( 1.0f,-1.0f, 1.0f);					// Top Right Of The Quad (Bottom)

		glVertex3f(-1.0f,-1.0f, 1.0f);					// Top Left Of The Quad (Bottom)

		glVertex3f(-1.0f,-1.0f,-1.0f);					// Bottom Left Of The Quad (Bottom)

		glVertex3f( 1.0f,-1.0f,-1.0f);					// Bottom Right Of The Quad (Bottom)

		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Red

		glVertex3f( 1.0f, 1.0f, 1.0f);					// Top Right Of The Quad (Front)

		glVertex3f(-1.0f, 1.0f, 1.0f);					// Top Left Of The Quad (Front)

		glVertex3f(-1.0f,-1.0f, 1.0f);					// Bottom Left Of The Quad (Front)

		glVertex3f( 1.0f,-1.0f, 1.0f);					// Bottom Right Of The Quad (Front)

		glColor3f(1.0f,1.0f,0.0f);						// Set The Color To Yellow

		glVertex3f( 1.0f,-1.0f,-1.0f);					// Top Right Of The Quad (Back)

		glVertex3f(-1.0f,-1.0f,-1.0f);					// Top Left Of The Quad (Back)

		glVertex3f(-1.0f, 1.0f,-1.0f);					// Bottom Left Of The Quad (Back)

		glVertex3f( 1.0f, 1.0f,-1.0f);					// Bottom Right Of The Quad (Back)

		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue

		glVertex3f(-1.0f, 1.0f, 1.0f);					// Top Right Of The Quad (Left)

		glVertex3f(-1.0f, 1.0f,-1.0f);					// Top Left Of The Quad (Left)

		glVertex3f(-1.0f,-1.0f,-1.0f);					// Bottom Left Of The Quad (Left)

		glVertex3f(-1.0f,-1.0f, 1.0f);					// Bottom Right Of The Quad (Left)

		glColor3f(1.0f,0.0f,1.0f);						// Set The Color To Violet

		glVertex3f( 1.0f, 1.0f,-1.0f);					// Top Right Of The Quad (Right)

		glVertex3f( 1.0f, 1.0f, 1.0f);					// Top Left Of The Quad (Right)

		glVertex3f( 1.0f,-1.0f, 1.0f);					// Bottom Left Of The Quad (Right)

		glVertex3f( 1.0f,-1.0f,-1.0f);					// Bottom Right Of The Quad (Right)

	glEnd();
	glDisable(GL_BLEND);// Done Drawing The Quad

	
	rotX += 0.3f;

	SwapBuffers(g_hDC);


}

///////////////////////////////// WIN PROC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

/////

/////	This function handles the window messages.

/////

///////////////////////////////// WIN PROC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*


LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 1; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized

		if(!g_bFullScreen)								// Do this only if we are NOT in full screen

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

			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle

		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene

		BeginPaint(hWnd, &ps);							// Init the paint struct		

		EndPaint(hWnd, &ps);							// EndPaint, Clean up

		break;

	case WM_KEYDOWN:
		switch(wParam) {								// Check if we hit a key

			case VK_ESCAPE:								// If we hit the escape key

				PostQuitMessage(0);						// Send a QUIT message to the window

				break;
		}
		break;
 
    case WM_DESTROY:									// If the window is destroyed

        PostQuitMessage(0);								// Send a QUIT Message to the window

        break; 
     
    default:											// Return by default

        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default

}
Edit: use the source tags in the future. [edited by - Null and Void on November 23, 2003 1:03:00 AM]
Calm down man...lol. Before going through all of your code, swear to me that the texture''s dimension are both powers of 2, and that you have enabled texturing. Also, is the file in the correct directory.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Advertisement
texture dimension? hmmm.... i don''t know... but its the right path to everything.

i tried with sphere mapping but it didn''t work so i did try to just get the texture mapping to work...
You may wana explain whats "not working"

Few pointers:

-Textures need to follow the 2^n rule. be (16X16, 32X32, 64X64, etc)
-Enable textures
-Don''t complicate things before you knwo somthings working (sphere maping)
Are you just getting an untextured polygon? Is the program bombing to the desktop? Did this ever get resolved?

Chris
No signature files!!! =)
are painting your texture on the right "side"
maybe your cube is textured from the inside
Pet
Pet

This topic is closed to new replies.

Advertisement