tilemap trouble
I believe your problems will be solved using glTexParameterf. The filtering and wrapping modes are set via that.
do something like this right after calling glTexImage2D (or when the tileset-texture is bound with glBindTexture):
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
hope this helps.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
hope this helps.
I use the following code and get the above result
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE );
When I use the code:-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE );
I get this result:-
As you can see, the weird wrapping seems to go, but those borders seems to apeare(?).
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE );
I get this result:-
As you can see, the weird wrapping seems to go, but those borders seems to apeare(?).
i think its your rendering of the tiles because in the clamp mode the gfx are correct its just that they are 1 pixel apart from each other.
nh = ( n / m_nW ); // +1
nh = m_nH - nh; // +1
possibly these 2 lines but i could not compile the code to test.
nh = ( n / m_nW ); // +1
nh = m_nH - nh; // +1
possibly these 2 lines but i could not compile the code to test.
No, that doesn't affect the result.
Here is the rendering code:-
This renders the map basicly.
Here is the Clip function:-
FillRenderList:-
This render code produces the above screen.
Because the tiles are 1px appart, I thought if I decresased the tile dimentions by 1px, then it would be ok. But in the Render method, when I decrement m_nTW and m_nTH, then increment them at the end of the method,
I get this result:-
Its a zillion times better, just not yet right.
If you look closely, I think the outer pixel of the tiles are missing...
Here is the rendering code:-
This renders the map basicly.
// this renders the layer inline bool Render( void ) { if ( POINTER_NULL( m_pSet ) ) return false; CTile* pTile = NULL; // saves on operators calls int nSize = 0; // number of tiles to render int i = 0; // counter int n = 0; // temp int nw=0,nh=0; // temp int idx = 0; // index var int mw = ( m_nSW > m_nW ) ? m_nW : m_nSW, // used to clamp small maps (see FillRenderList() w) mh = ( m_nSH > m_nH ) ? m_nH : m_nSH; // used to clamp small maps (see FillRenderList() h) // clip Clip( ); // render the layer for ( int h = 0, th = 0; h < mh; h++, th += m_nTH ) for ( int w = 0, tw = 0; w < mw; w++, tw += m_nTW ) { // get the tile index idx = w + ( h * mw ); n = *m_pnRenderList[ idx ]; idx = *m_Layer[ n ]; if ( idx == -1 ) continue; pTile = m_pSet->GetTile( idx ).GetData( ); // set the tiles position pTile->SetScale( m_fSW, m_fSH ); nh = ( n / m_nW ) + 1; nh = m_nH - nh + 1; nw = ( ( n ) % m_nW ); pTile->SetPos( -( ( m_fXOff )-( m_nTW * m_fSW * nw ) ),( -m_fYOff )+( ( m_nTH * m_fSH * nh ) ) ); // render the tile pTile->Render( ); } // end for w return true; } // end Render
Here is the Clip function:-
// this clips the map inline bool Clip( void ) { // fill in the render list //float f = 0.0f; // temp //f = GetTrueHeight( ) / ( ( m_nSH+1.0f ) * m_nTH * m_fSH ); //f = 1.0f / f; FillRenderList( ( m_fXOff / ( m_fSW * m_nTW ) ), -( ( ( m_fYOff-( GetTrueHeight( )-g_nScreenHeight ) ) / ( m_fSH * m_nTH ) ) ) ); return true; } // end Clip
FillRenderList:-
// this fills in a render list inline void FillRenderList( int nX, int nY ) { int x = 0, y = 0, n = 0, n2 = 0; // temp and counters int w = m_nSW, h = m_nSH; // used to make sure there are not weird things happening if the map is smaller than the screen // clamp if ( nX < 0 ) nX = 0; if ( nY < 0 ) nY = 0; if ( ( nX + m_nSW ) > m_nW ) nX = m_nW - m_nSW; if ( ( nY + m_nSH ) > m_nH ) nY = m_nH - m_nSH; if ( m_nSW > m_nW ) { nX = 0; w = m_nW; } // end if if ( m_nSH > m_nH ) { nY = 0; h = m_nH; } // end if // fill in the render list for ( y = 0; y < h; y++ ) { for ( x = 0; x < w; x++ ) { // get the idxs n = x + ( y * w ); n2 = x + nX + ( ( nY + y ) * m_nW ); // set the idx m_pnRenderList[ n ] = n2; } // end for x } // end for y } // end FillRenderList
This render code produces the above screen.
Because the tiles are 1px appart, I thought if I decresased the tile dimentions by 1px, then it would be ok. But in the Render method, when I decrement m_nTW and m_nTH, then increment them at the end of the method,
inline bool Render( void ){ //.... --m_nTW; --m_nTH; //Render the tiles loop ++m_nTW; ++m_nTH;} // end Render
I get this result:-
Its a zillion times better, just not yet right.
If you look closely, I think the outer pixel of the tiles are missing...
Quote:Original post by rpg_code_master
Here is the rendering code:-
Really, you posted everything but the rendering code. The rendering process is the line or lines of code that put the graphics on the screen, not the various tile-shuffling that leads up to that. Having said that, I expect the problem is in that scaling and positioning. Why not simplify all that and substitute in a few constants to narrow down where the error is introduced. Or print some of the coordinates to a file so that you can analyze whether the tiles are being spaced too far apart, or if the texture coordinates are set incorrectly.
Anyway, you'll want to keep the GL_CLAMP, and I don't see a call for GL_NEAREST_MIPMAP_NEAREST over GL_NEAREST unless you definitely need mipmaps.
why not substitute one of the tiles for a tile with a different colour on all four sides of the tile eg red at top green on left blue on right white on bottom that will show if any of the gfx is missing.
try taking shifting by another pixel
just to see what affect it has.
try taking shifting by another pixel
inline bool Render( void ){ //.... --m_nTW; --m_nTH; --m_nTW; --m_nTH //Render the tiles loop ++m_nTW; ++m_nTH; ++m_nTW; ++m_nTH;} // end Render
just to see what affect it has.
I've had a very similar problem with DirectX, I'd didnt solve it but I another project my mapping was off and it was because my bitmap template of tiles was not a ^2 size (eg, 128x128, 256x256, 512x512 etc). I used the EXACT same code and it worked with ^2 sized template and not without.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement