Results 1 to 10 of 121

Thread: G.T.A.2 Map Editor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I wanted to work on this thing again and once again, taking a break from project helps.
    I found good tutorial and example for handling NPOT textures here:

    http://lazyfoo.net/tutorials/OpenGL/...ures/index.php

    So i took some NPOT textures from GTA2 and and they all are rendered correctly.
    I have to use DevIL with Delphi and additional DLL's but the result is awesome.


    What's even more important and awesome for me is that these are all quads rendered with OpenGL and textured with NPOT textures. This is exactly what i wanted.
    And if i understand correctly they all are centered. It was very hard for me to make work, but that example solved this.

    Im not sure if i can get rid of the DevIL but if yes, tell me.
    I was so excited so i even didn't properly read the source and what it does exactly.
    If it's possible to get rid of it, i will use nxPascal stuff.

    Here are few examples

  2. #2
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    in newer versions of opengl textures need not be powers of 2 to work. I create many textures on the fly and none of them are powers of 2 and they render fine.

  3. #3
    Quote Originally Posted by Carver413 View Post
    in newer versions of opengl textures need not be powers of 2 to work. I create many textures on the fly and none of them are powers of 2 and they render fine.
    I read somewhere that although non power of 2 textures are supported, the power of 2 will get better performance. I would like to know how much better performance...

  4. #4
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    Quote Originally Posted by Rodrigo Robles View Post
    I read somewhere that although non power of 2 textures are supported, the power of 2 will get better performance. I would like to know how much better performance...
    I read somewhere that opengl actually expands these internally so they end up as power of 2 anyway. the advantage would be in the passing of smaller texture or maybe thats where the slowdown occures. best practice of course would be to try to put them on a single texture and map them properly

  5. #5
    I have old PC with old gfx card ATI Radeon 9550. And i want to support old hw and os starting from Windows 95. Better don't ask why. I love the old stuff and software. I dunno, if nxPascal GL code supports W95, with the latest possible OpenGL dll in it. I will try with my editor. I don't use any shaders or anything in my editor and "biggest" textures are 64x64.
    Just the sprites from GTA2 files are different, like 16x78, 2x28 etc. I don't use any texture atlas, they seem to be too complicated for me.

    Te DevIL actually seems to have bug or im just not doing enough or doing something wrong but NPOT .bmp files are completely screwed when rendering them with same code. PNG works fine. I havent tried the pure pixels from pointer. Will do this later, hopefully it will work.

  6. #6
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    NPOT : No need to re-scale the image or anything like that in order to support NPOT textures, just simply create an image which snaps to the next largest power of two size on both axis, then load your image data into the 0,0 corner and then rescale your texture co-ordinates by the ratio of the new NPOT image size to the Original image size. You waste some texture memory but it's quicker to load the textures (As you don't need to scale them). If all the GTA2 textures are loaded on map startup and nothing is streamed during gameplay, you may as well rescale like you are in order to save wasting memory.

    EDIT : totally ignore that, if you're scaling the images for POT anyway then you won't use any more GPU memory using the method I suggested. it'll be quicker than scaling and you won't have a DevIL (or other image lib) dependancy.

    A Texture atlas would let you save memory and would also be faster when rendering (less texture switching) it's really easy, for the first image you create the biggest texture you can for your hardware (256x256 should be fine for example) and load it into the top corner, then return that images GL_ID and the texture coords that are used. Then for each sucessive image you 'search' your available space in your 'texture atlas' for a clear spot that your image will fit in (so look at the dimensions of existing images, itterating along X and Y until you've found some free space) then copy your image data there, then return the coords that were found for use for the new reference.

    If your search doesn't find a space big enough for the image due to all the other images, you just create another big texture in GL and start the process all over again.

    The end result is a handfull of big textures with all your small textures splattered across them and all your material/texture references are to these images and coord offsets to the actual image data you want.

    There's all kinds of ways of doing it, different optimizations to use etc but the basic principal is sound. Look at light-map construction in a BSP map loader for an example, you can also read up on the design of ID Software's mega-texturing implementation in RAGE. Essentially the same technique but creates super large images in system memory, portions of which are copied to GPU memory when needed. RAGE (tech 5 or whatever) has algorithms (at map compile stage) that try to group required textures together in the mega-texture so when the 'atlas' portion is copied to a normal texture you're using most of the sub-textures for the on-screen geometry. They probably use visbility determination, portals etc as part of the algorithm to optimize the grouping of sub-textures.
    Last edited by phibermon; 30-03-2013 at 06:03 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  7. #7
    Thank your for your reply. Yes i got 2 good examples actually which create opengl texture from npot bitmaps, one is that DevIL and one is with SDL. They load texture fine but biggest problem for me now is rendering quad which has the newly created texture centered exactly on the quad.

    I even did a simple example with crosshair on screen and rotated the quad on center and then i discovered that texture is not actually centered on the quad.

    The quad itself was "perfect", npot texture was also OK but texture had offset on the quad. But in my case the npot texture must be exactly centered on the quad.

    So have discovered that im unable to center the texture on quad. As you said: "rescale your texture co-ordinates by the ratio of the new NPOT image size to the Original image size"

    I don't care about memory atm, i need to make it work first.

    Im now even unable to find the example i wanted to show you, how the texture is not centered.
    I was so disappointed. I thought i got it finally working but no, again some bug or problem.

    But i would like to make it work. I will at least learn something from it.
    I will try to find the example i made and post a screenshot later.


    EDIT
    It should be like in image B, but atm its like A. Which is bad!
    It should be centered perfectly like in image B.
    Original texture size is 32x18





    By ratio you mean in this case 32 / 32 and 18 / 32 ?

    Since next POT for 32 is 32 (unchanged in this case) and for 18 it's 32.


    Here is the way im doing atm:
    Code:
     
    var texTop, texbottom, texleft, texright:single;
    w,h:Single;
    
    
      texTop:=0; // This shouldnt be 0 i think, must be calculated?
      texleft:=0; // This shouldnt be 0 i think, must be calculated?
      texbottom:=th /getnextpot(th);
      texright:=tw / getnextpot(tw);
    
    
      w:=tw/64;
      h:=th/64;
    
    
    
    
    
    glBegin( GL_QUADS );
             // Top-left vertex (corner)
             glTexCoord2f( texLeft,    texTop ); glVertex3f( -w/2, -h/2, 0 );
    
             // Bottom-left vertex (corner)
             glTexCoord2f( texRight,    texTop); glVertex3f( w/2, -h/2, 0 );
    
             // Bottom-right vertex (corner)
             glTexCoord2f(  texRight, texBottom); glVertex3f( w/2, h/2, 0 );
    
             // Top-right vertex (corner)
             glTexCoord2f(texLeft, texBottom); glVertex3f( -w/2, h/2, 0 );
    
       glEnd();
    If i modify either texTop and / or texLeft then i can move texture to center.
    But then it looks pretty bad, like squeezed together a bit or something.

    "tw" and "th" are NPOT image width and height, assigned on image loading!
    In this case they contain: 32 and 18.

    This code causes things look like in image A.

    I divide by 64 because every tile in GTA2 is 64x64. Main gfx. Every object like this roadblock is placed on the tiles of size 64x64.

    It seems everything should be calculated. But whats the correct math?
    I will try to find some example on net.

    Texture centering is the only problem atm.
    Last edited by hwnd; 31-03-2013 at 01:51 PM.

  8. #8
    Quote Originally Posted by hwnd View Post
    If it's possible to get rid of it, i will use nxPascal stuff.
    Yes nxPascal supports NPOT textures. There should also be demo that shows drawing 2D centered, and it allows rotation point be anywhere in (or out of) the image. Demos use POT texture sizes only because they are most compatible, but you can freely edit the images in Paint/Gimp or other and any size would work.

    Also the link you gave http://lazyfoo.net/tutorials/OpenGL/...ures/index.php is not actually using NPOT but it's putting small picture into larger 1024x256 texture with black pixels outside. That's not best way to handle it, although as i have mentioned before, is also possible with nxPascal through texture options...
    Last edited by User137; 25-03-2013 at 02:37 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •