Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ugly TGA textures

Posted on 2004-03-27
9
Medium Priority
?
723 Views
Last Modified: 2013-12-06
Hi All,

I've little OpenGL problems!

I am building an OpenGL application in Delphi using TGA textures files(480x480). I use my BuildList function to create pieces of this big texture. Every thing works fine! But the problem is: "when i've loaded the textures and paint them on screen, (1.) there are some (ugly) lines around my texture (2.) and my texture is smooth (I DONT LIKE THAT)"

See my screenshot here :
http://www.kiwifreak.com/help.gif

Load Texture with:
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

Draw the tile with:
  glBegin(GL_POLYGON);
    glTexCoord2f [...]
    glVertex2f [...]
  glEnd;


Thanks for your veryvery mucht for help!

Sander
0
Comment
Question by:KiwiFreaK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
9 Comments
 

Author Comment

by:KiwiFreaK
ID: 10698195
NOTE: I use GL_BLEND
Please help me!
0
 
LVL 8

Expert Comment

by:_corey_
ID: 10846220
Does glShadeModel(GL_FLAT); have any affect?
0
 
LVL 8

Expert Comment

by:_corey_
ID: 10846244
Also, have you tried using GL_QUADS and making sure it looks right or the same(bad) on a quad the exact size of the texture?

what are the vertices you're using in that polygon?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:KiwiFreaK
ID: 10880954
Haai,

Thanks for your reply!
I've tried "glShadeModel(GL_FLAT); ", no effect!
Yes, i've also tried GL_QUADS, it doen't matter; the same smooth textures!


This is my BuildList Function:

function BuildList(baseofbase,t_row,t_col,dem : integer; t_resource : Gluint) : integer;
var
  loop : integer;
  cx,cy,demension,tile_border,texture_borderY,texture_borderX : single;
  maxlist : Integer;
begin
  base := baseofbase;
  maxlist := t_row*t_col;
  demension := (dem / 2);
  tile_border := 0.0;
  texture_borderY := 0.001;
  texture_borderX := 0.001;
  for loop := 0 to maxlist-1 do
  begin
    cx := (loop mod t_col) / t_col;
    if (loop mod t_col = 0) then
      cy := (loop / t_row) / t_row;
    glNewList(base+loop,GL_COMPILE);
    glBindTexture(GL_TEXTURE_2D, t_resource);
      glBegin(GL_QUADS);
        glTexCoord2f(texture_borderX+cx                  ,texture_borderY+((1.0-cy)-(1.0 / t_row)));  glVertex2f(-demension-tile_border, +demension+tile_border);
        glTexCoord2f((cx+(1.0 / t_col))-texture_borderX  ,texture_borderY+((1.0-cy)-(1.0 / t_row)));  glVertex2f(+demension+tile_border, +demension+tile_border);
        glTexCoord2f((cx+(1.0 / t_col))-texture_borderX  ,(1.0-cy)-texture_borderY);                  glVertex2f(+demension+tile_border, -demension-tile_border);
        glTexCoord2f(texture_borderX+cx                  ,(1.0-cy)-texture_borderY);                  glVertex2f(-demension-tile_border, -demension-tile_border);
      glEnd();
    glEndList();
  end;
  result := base;
end;
0
 
LVL 2

Expert Comment

by:enkimute
ID: 10947698
to get non smooth textures :

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

To fix the border pixels, consider the following.

1. textures are addressed with coordinates x and y where 0 <= x < 1 and 0 <= y < 1.
2. When a polygon is rasterized from x1 to x2, then the same rule is used, namely x1 <= pixelpos < x2 (This means that the last pixel, the one on x2 is NOT drawn).
3. Combine 1 and 2 to see that the texture at 1.00 is not referenced because the pixel at x2 is not drawn.
4. When using gl textures, you have to tell gl what to do with pixels that have texture coordinates not in the range specified above. The basic options are :
      - wrap .. texture is repeated.
      - clamp .. texture border pixel is repeated.
    You tell this to the gl by :
   
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    or if you want clamping :
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

Ok, also keep in mind that the glTexParameterf calls change the texture state for the currently bound texture object !
Also, notice that GL_CLAMP means something different for textures that are specified with a border (at the glteximage2d command).
If you have a border, the border color (which you set using glTexParamterfv(GL_TEXTURE_2D, GL_BORDER_COLOR, &color)) is repeated.
If you don't have a border, the texture image last pixel is repeated.

A simple code example to draw a quad with a texture looks something like this :

// Bind texture target.
  glBindTexture(GL_TEXTURE_2D, mytexture);
// Disable texture interpolation
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Set up projection matrix.
  glPushMatrix();  
  glLoadIdentity();
     glTranslatef(0,0,-10);
   // Draw textured quad.
     glBegin(GL_QUADS);
       glTexCoord2f(0,0); glVertex2f(-2,-2);
       glTexCoord2f(1,0); glVertex2f(2,-2);
       glTexCoord2f(1,1); glVertex2f(2,2);
       glTexCoord2f(0,1); glVertex2f(-2,2);
     glEnd();
  glPopMatrix();




0
 
LVL 17

Accepted Solution

by:
davebytes earned 1200 total points
ID: 11019484
More specifically, I'd really suggest making the source artwork a power of 2 if you can.  Even with modern videocards, there are wins to it being pow2 on both edges.  Doesn't need to be square.

So, either up-rez to 512x512, or down to 256x256.  That'll get rid of all the excess issues.  Then point filtering will get rid of the smoothing.

Note that it is RARE for developers to not use LINEAR filtering (or bilinear, or trilinear).  The results are really blocky.  Unless you are doing a fixed-pixel engine, such as a sprite blitter via GL.

d
0
 
LVL 2

Expert Comment

by:enkimute
ID: 11021141
If you dont want to, you dont have to resample your picture ..

You can easily call glTexImage2D with 512x512, and NIL as the data pointer.
then call gltexsubimage2d to put your 400x400 bitmap in the upper left corner of this texture.

Then scale your texture coordinates. for example like this ..

glmatrixmode(gl_texture);
  glscalef(1*400/512,1*400/512,1);
glmatrixmode(gl_modelview);

or by passing scaled coordinates off course ..
This destroys wrapping behaviour off course ..
0
 
LVL 17

Expert Comment

by:davebytes
ID: 11021986
I specifically said to do pow2 so that you get full wrapping behavior, no odd edges.  If this is a sprite-based game, then he'll be clipping coordinates anyway as part of the polygon rendering, no need to play with the texture matrix.  Otherwise, the move to pow2 textures will save a lot of pain in the future, especially on older hardware, when wrapping, etc.

d
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question