Solved

Ugly TGA textures

Posted on 2004-03-27
9
694 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
  • 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 400 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now