Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Sa Dez 21, 2024 12:59

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Drawing Texture Atlas's Properly
BeitragVerfasst: Sa Okt 30, 2010 04:16 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Iv come up with the following code to draw from a Texture Atlas to a face, but it draws what looks like a border around the face using parts of the texture which are lying outside of the area i told OpenGL to draw from.

// Input is the standard texture coordinates (For rendering the whole texture on the surface)
Code:
function TTextureSurface.BuildTexCoord(BaseX,BaseY : Double) : TVec2d;
begin
 Result := SetVec2d(BaseX,BaseY);

 if not Assigned(FTexture) then
  Exit;

 Result[0] := Result[0]*((16)/FTexture.GetActualWidth); //16x16 is the size of the individual texture on the Atlas
 Result[1] := Result[1]*((16)/FTexture.GetActualHeight);

 Result[0] := Result[0] + (FXPos)/FTexture.GetActualWidth;
 Result[1] := Result[1] + (FYPos)/FTexture.GetActualWidth;
end;


If i reduce the size of the area OpenGL is taking the image from it does "Fix" the problem, but i was wondering if there was a better solution than not rendering part of the image.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Drawing Texture Atlas's Properly
BeitragVerfasst: Sa Okt 30, 2010 10:20 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
First of all:
Code:
Result[1] := Result[1] + (FYPos)/FTexture.GetActualWidth;

This should be "Height" ?


If you want to target an exact texel inside a texture, use this:
Code:
textureCoord = (0.5 + texelCoord) / textureSize

where:
textureCoord : 0...1
texelCoord : 0...15
textureSize : 16


Using this I get:
Code:
localTextureCoord = (0.5 + localTexelCoord) / localTextureSize
<=> localTextureSize * localTextureCoord - 0.5 = localTexelCoord


and to global texelCoords:
Code:
globalTexelCoord = (localTextureSize*tilePosition) + (localTextureSize * localTextureCoord - 0.5)
=>
globalTextureCoord = (0.5 + globalTexelCoord) / globalTextureSize


So we get:
Code:
result[0] = (0.5 + (16*FXPos + 16*BaseX - 0.5)) / FTexture.GetActualWidth;
result[1] = (0.5 + (16*FYPos + 16*BaseY - 0.5)) / FTexture.GetActualHeight;

Maybe you need to use just "FXPos" instead of "16*FXPos", depending what FXPos exactly is.

Zitat:
but it draws what looks like a border around the face using parts of the texture which are lying outside of the area i told OpenGL to draw from.

In any way you will need a border around each image. Especially when using mipmaps, because then the image gets scaled down and the colors are mixed. However, because your local textures are size power of two (16) it might work even with mipmaps.

Edit: You might also want to try to clamp locale localTexelCoord to range 0....localTextureSize-1.

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Drawing Texture Atlas's Properly
BeitragVerfasst: Sa Okt 30, 2010 14:07 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
The 0.5's cancel each other out in your code. FXPos is the X Position and FYPos is the Y Position(In Pixels). Multiplying it by 16 would make it an invalid coordinate.

Zitat:
In any way you will need a border around each image.


I can't modify the image. Its from a game, my app loads the levels of the game. So that its compatible with future updates to the game (And its textures) i can't make my own textures. Game doesn't suffer from the border problem and it uses OpenGL. Mipmaps arn't a problem as im not using any (Textures are 8bit style, so im just using GL_NEAREST)

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.009s | 15 Queries | GZIP : On ]