Texture problems

Started by
5 comments, last by tre 15 years, 1 month ago
Hi, I've been working on a project for some time now and as time has passed, my code have become very messy. In an attempt to clean everything up in structures, headers and cpp's, I now find that my TGA-loader function no longer, well, functions and I'm at a complete loss. I'm also doing this restructuring for the purpose of trying to get a functional gluLookAt-camera with quaternions. When running the "old" code everything is working fine, now when I'm trying to use the same code in my new program the texture turns out like this: OpenGL Texture error I'm using NeHe's base code and did the tutorial for a TGA-loader (quite a newbie here). LoadGLTextures (main.cpp)

bool LoadTGA(Texture *, char *);
Texture texture[2];

int LoadGLTextures(){
	int Status = false;

	if (LoadTGA(&texture[0], "data/globe.tga") && LoadTGA(&texture[1], "data/starmap.tga")){
		Status = true;

		glGenTextures(2, &texture[0].texID);

		glBindTexture(GL_TEXTURE_2D, texture[0].texID);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, texture[0].width, texture[0].height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture[0].imageData);
		
		glBindTexture(GL_TEXTURE_2D, texture[1].texID);
		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, texture[1].width, texture[1].height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture[1].imageData);

		if(texture[0].imageData){
			free(texture[0].imageData);
		}
		if(texture[1].imageData){
			free(texture[1].imageData);
		}
	}
	
	return Status;
}



Draw (main.cpp)

void Draw (void){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	SetupLights();

glLoadIdentity();
gluLookAt( 0.0f,  1.0f,  50.0f,     0.0f,  0.0f,  0.0f,     0.0f, 1.0f, 0.0f);

		GLUquadric *q = gluNewQuadric();
		gluQuadricNormals(q, GLU_SMOOTH);
		gluQuadricTexture(q, GL_TRUE);

		glBindTexture(GL_TEXTURE_2D, texture[0].texID);
		gluQuadricOrientation(q, GLU_OUTSIDE);

			gluSphere(q, 10.0f, 4096, 4096);
			glTranslatef(20.0f, 0.0f, 0.0f);
			gluSphere(q, 10.0f, 4096, 4096);

	glFlush();
}



Another problem I'm having is this part:

case WM_KEYDOWN:
        if((wParam >= 0) && (wParam <= 255)){
		window->keys->keyDown[wParam] = true;
		return 0;
	}
	break;



Dev-C++ is telling me that this is will allways ">= 0", still just a warning but it's irratic, sometimes it pops up, sometimes it doesn't. The really annoying this is that all the code is the exact same that I'm using for my other program. NeHe's base code is just copied and the TGA-loader is also just copied. I'd really appreciate the help :) Thanks! Marcus
Advertisement
Hi,
Are you enabling the texture2d target using glEnable(GL_TEXTURE_2D); before u bind the texture to the texture2d target?
See this

See if this helps,
Mobeen
Proud to be a PAKISTANI.
I believe I am, the program loop is waiting for initialization before calling any drawing:
	while(g_isProgramLooping){		window.init.isFullScreen = g_createFullScreen;		if (CreateWindowGL(&window) == true){			if (Initialize(&window, &keys) == false){				TerminateApplication (&window);                        }else{				isMessagePumpActive = true;				while (isMessagePumpActive == true){					if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0){						if (msg.message != WM_QUIT){							DispatchMessage (&msg);						}else{							isMessagePumpActive = false;						}                                        }else{						if (window.isVisible == false){							WaitMessage ();						}else{							tickCount = GetTickCount ();							Update (tickCount - window.lastTickCount);							window.lastTickCount = tickCount;							Draw();							SwapBuffers (window.hDC);						}					}				}			}			Deinitialize ();			DestroyWindowGL (&window);		}else{			// fel vid skapande av fönster			MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);			g_isProgramLooping = false;		}	}


This is part of NeHe's OpenGL base code.
In that case, I would recheck the tga image loading code. Recheck the image loaded to make sure that the texture formats and other flags for glTexParam... are correct. Maybe just disable the targa loading code and replace it with a simple in memory texture like a checker pattern using something like this and see if this works alright.
GLubyte pixels[16]={0};int count=0;for(int i=0;i<4;i++){   for(int j=0;j<4;j++)   {      if( (i<2 && j<2) || (i>=2 && j>=2))	  pixels[count] = 255;      count++;   }}glGenTextures(1,&textureID);glBindTexture(GL_TEXTURE_2D, textureID);// set the texture parametersglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexImage2D(GL_TEXTURE_2D,0,GL_INTENSITY,4,4,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,pixels);
Proud to be a PAKISTANI.
This is sorta off-topic, but that pic looks a lot like those images generated by complex mathematical algorithms (fractals and such) o_O

Quote:Original post by tre
Another problem I'm having is this part:
*** Source Snippet Removed ***
Dev-C++ is telling me that this is will allways ">= 0", still just a warning but it's irratic, sometimes it pops up, sometimes it doesn't.

Isn't wParam unsigned? Unsigned values are always >= 0, thereby making that check useless as it'll always be true.

EDIT: by the way, it may look erratic because I think the warnings don't pop up if you rebuild without making any changes (at least that's what happened last time I used Dev-C++). Whatever, my statement holds true.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
@mobeen
The code you provided gave me this result:
new texture error
I don't know what I'm doing wrong...


@Sik_the_hedgehog
So that's the reason. Thanks! I guess I could just pull that statement then.
Hi folks,
and thanks to those who helped me. I went through the entire code from start to finish and found no errors or anything that could get mis-interpreted.
So I took a shower and started thinking about the image files.

True to Ockhams Razor, I took the simplest answer and went at it. I tried different image sizes, compressions (uncompressed too), different bits and so on. Finally I completely deleted the files and created new ones from GIMP, and hey presto! TEXTURES!

solved texture error

This topic is closed to new replies.

Advertisement