Am I loading my Textures in the right order
I have 2 textures, that refuse to display on the screen. Instead, I get a repeating pattern of blue diamonds (Blue was the last colour drawn on the screen, so I guess that this is where the colour comes from)
My program works in the following order,
On the Application (MFC) being created,
Initialise OpenGL
Get DC, Set Pixel Format, Create HDC, Make Current.
Load and bind 2 Textures (using standard NeHe code)
Then I call the following in this order,
glEnable( GL_TEXTURE_2D )
glShadeModel(GL_SMOOTH)
glClearColor(0.0f, 0.0f, 0.0f, 0.5f)
glClearDepth(1.0f)
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
My Drawing Function does the following (again in order)
Push Matrix, Translate, Set Colour, Rotate, Draws the 2 textures (again standard NeHe), Pops the Matrix Swaps the Buffers
I didn''t want to just dump my functions in here if anyone can look at that and say just swap operations X and Y around.
Can anyone suggest what is going on here ? - The Tiles are 64 * 64, and each is 2 colours, none of the colours on the tiles are being displayed
Thanks in advance,
Bp
I''m not somewhere where I can test this, but you''re trying to load textures before you enable texturing. I can see openGL being unable to bind a texture without texturing enabled.
I would try calling:
glEnable( GL_TEXTURE_2D )
glShadeModel(GL_SMOOTH)
glClearColor(0.0f, 0.0f, 0.0f, 0.5f)
glClearDepth(1.0f)
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
Before you load and bind the textures.
How it works,
Will
I would try calling:
glEnable( GL_TEXTURE_2D )
glShadeModel(GL_SMOOTH)
glClearColor(0.0f, 0.0f, 0.0f, 0.5f)
glClearDepth(1.0f)
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
Before you load and bind the textures.
How it works,
Will
Thanks Will, but that made no difference.
Most of the code is standard NeHe, so it has to be me, I just can''t see where.
Any other takers ?
Bp.
Most of the code is standard NeHe, so it has to be me, I just can''t see where.
Any other takers ?
Bp.
Did you remember to glColor3f(1,1,1) before you drew your textures?
This may not be your problem, but it never hurts to try.
This may not be your problem, but it never hurts to try.
I''m just wondering if you''re mapping the textures to quads, or trying to just draw the pixels to the screen...
-noix-
In this world gone mad, we won''t spank the monkey; the monkey will spank us.
-noix-
In this world gone mad, we won''t spank the monkey; the monkey will spank us.
Yep, mapping to quads.
That bit of code is straight off NeHe, so I didn''t see the point in posting it.
Bp
That bit of code is straight off NeHe, so I didn''t see the point in posting it.
Bp
Maybe you should also post the code where you bind the texture and especially the part where you actually do the drawing. Maybe your drawing routine is bad or you are using bad texture coordinates (on 2nd thought: No, that wouldn´t alter the color of your texture). Also, I don´t really understand why you are binding your textures in the intialisation phase. AfaIk binding (we are speaking of the glBindTexture() command, are we?) is used to tell openGL that the following objects shall have the specified texture on it. If You do that on init you will have the 2nd texture for all objects.
Well I moved things about Atheist, and still no joy.
ok, heres the current initialisation code.
And here is my drawing routine
I hope that you can spot the obvious mistake, cos I can't and my head is starting to hurt now.
Bp.
-Edit - swapped code tags for source tags
[edited by - Bagpuss on August 8, 2003 12:39:49 PM]
ok, heres the current initialisation code.
glEnable( GL_TEXTURE_2D );glShadeModel(GL_SMOOTH);glClearColor(0.0f, 0.0f, 0.0f, 0.5f);glClearDepth(1.0f);glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);LoadGLTextures(); //What if this fails}int CTileEngine::LoadGLTextures(){ AUX_RGBImageRec *TextureImage[2]; TextureImage[0] = LoadBmp("E:\\Coding_Projects\\OpenGL_Tile_Engine\\Version1\\Brown1.bmp"); TextureImage[1] = this->LoadBmp("E:\\Coding_Projects\\OpenGL_Tile_Engine\\Version1\\Green1.bmp"); glGenTextures(2, &texture[0]); //Associate the Bound Texture to a 2D Texture glBindTexture(GL_TEXTURE_2D, texture[0]); //Load in the Texture Data from a Loaded Bitmap glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); //Set the Texture Parameters - Does this need to be done twice ? glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data); //Set the Texture Parameters glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);#ifdef _DEBUG UINT glErrorCode = 0; glErrorCode = glGetError(); TRACE("Loading Textures = %d\n",glErrorCode);#endif for (int t = 0; t < 2; t++) { if (TextureImage[t]) { if (TextureImage[t]->data) { free(TextureImage[t]->data); } free(TextureImage[t]); } } return(1);}
And here is my drawing routine
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen and the depth bufferglPushMatrix(); //Save a Copy of the matrix onto the stack int tile;glTranslatef(200.0f,50.0f,2.0f);glColor3d(0.0f,0.0f,255.0f);glRotatef( 45.0f, 0.0f, 0.0f, 1.0f ); int a=0,b=0;for (int y = 0; y<4; y++){ for (int x = 0;x<4; x++) { tile = map[y][x]; a = y*64; b = x * 64; glBindTexture(GL_TEXTURE_2D, texture[tile]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(float(b), float(a), 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(float(b + 64), float(a), 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(float(b + 64), float(a + 64), 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(float(b), float(a + 64), 0.0f); glEnd(); }}#ifdef _DEBUG UINT glErrorCode = 0; glErrorCode = glGetError(); TRACE("Drawing Scene - Draw Tiles = %d\n",glErrorCode);#endifglPopMatrix();#ifdef _DEBUG glErrorCode = 0; glErrorCode = glGetError(); TRACE("Drawing Scene - Pop Matrix = %d\n",glErrorCode);#endifBOOL test = SwapBuffers(m_pDC->GetSafeHdc());#ifdef _DEBUG glErrorCode = 0; glErrorCode = glGetError(); TRACE("Drawing Scene - Swap Buffers = %d\n",glErrorCode);#endif}
I hope that you can spot the obvious mistake, cos I can't and my head is starting to hurt now.
Bp.
-Edit - swapped code tags for source tags
[edited by - Bagpuss on August 8, 2003 12:39:49 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement