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
    Ok, here is the image i use for testing.




    As you see it already as offset. But how GTA2 centers them anyway then?
    It must somehow compensate that offset.

    One idea i had is to go thru the image, ignore all black pixels and center rest of the image in new image. Black pixels in GTA2 are always used for transparency.
    So i can ignore them. But such image processing will slow things down i guess.
    I dont know.

    I want to rotate these things around, thats why it must be centered, if its not then it will look ugly when rotating and it will do it not correctly. For just moving around the offset doesnt matter for me.

    OK, very "hacky" solution is ignore all this and leave it as is and just rotate and move as needed. If rotation with offset moves sprite away from correct position on map then just move it back. Not very good but if i will give up i will do it.

    Seems the code im using is used widely:
    http://gitorious.org/racr/mainline/b...c/r_opengl.cpp

    So it's not the code but actual GTA2 sprites that are done in so stupid way.


    I have a c++ code from friend who created texture atlas with all sprites packed together in 2048x2048 sheet. Just like you suggested.
    All the odd sizes of sprites in it, directly from GTA2 files and he uses them with no problems.
    Automatic uv coord generation etc. Dunno exactly what he does there.

    Have to ask or look at the source more closely. I could do this already but i thought i will get it work in simpler way. His code is not easy one.

    For some reason i don't like texture atlas things, i think its too complicated for me.


    EDIT


    Maybe instead of centering actual quad he centers the sprite itself?
    Sprite W, H, and offset thingy. Centering images is easy, at least in 2D.

    This would work in my case for map editor i think.

    But if we talk about game collision then he shoots a ray in 4 directions from ped center and tests for collisions with nearby obstacles / walls. So actual sprite quad is not used in collision testing.


    Dunno.
    Last edited by hwnd; 31-03-2013 at 03:32 PM.

  2. #2
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    If the source image is exactly this, but it's stored as NPOT, then it's almost certainly *supposed* to be offset from the center due to it's use in the game (try some other images, try some cars etc). If not then there simply must be additional information in the game data somewhere that gives you the true image size.

    The point is that you shouldn't have to remove any pixels, if it's NPOT then why didn't they save it clipped to the visible pixels in the first place? why did they waste space? and if so, where's the additional information telling them what the usable portion of the image is?

    Removing black pixels is not a good idea, you can't be sure that the original artist didn't actually have some blank pixels down one side, this can't possibly be the solution because why would they have this additional costly step in a commercial game when they could of just stored the image without unused pixels?

    Again, if this is the source image then it's supposed to look like (A) (with transparency) in the game, your solution is correct, it's correctly mapping the source image you posted to the quad only by modifying the texture coods. it's the source image that has the blank space, not as a result of your calculations.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  3. #3
    I think you are almost there, but it's unclear why some other also have offset. Like peds:
    Right side has offset:



    In my friends renderer he deals with "alignment"
    He draws peds with alignment like this:

    Code:
       if (align){         VBO.Add(Vector3f(pos.x+w/2,pos.y+h/2,pos.z),Vector2f(texEntry->U2,texEntry->V2));
                VBO.Add(Vector3f(pos.x+w/2,pos.y-h/2,pos.z),Vector2f(texEntry->U2,texEntry->V1));
                VBO.Add(Vector3f(pos.x-w/2,pos.y-h/2,pos.z),Vector2f(texEntry->U1,texEntry->V1));
                
                VBO.Add(Vector3f(pos.x+w/2,pos.y+h/2,pos.z),Vector2f(texEntry->U2,texEntry->V2));
                VBO.Add(Vector3f(pos.x-w/2,pos.y-h/2,pos.z),Vector2f(texEntry->U1,texEntry->V1));
                VBO.Add(Vector3f(pos.x-w/2,pos.y+h/2,pos.z),Vector2f(texEntry->U1,texEntry->V2));
    }
    He does some addition and dividing. "Pos" struct is (X,Y,Z) position to draw ped at, "W" is ped sprite width (NPOT).

    I should try to make minimal app with this VBO and use my texture, maybe it actually solve this.
    Im not sure.



    EDIT

    Ok, i think you are correct that this actually should be like this.
    if you look at the ped above, it's centered. I tried some other peds and objects.
    They seem to be centered enough.

    I think that's it. It's just supposed to be like that.

    Another ex:
    Black borders but c. car is centered:



    Thank you for helping.
    Last edited by hwnd; 31-03-2013 at 04:02 PM.

  4. #4
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    it looks like VBO in this example is a class he's created that constructs a GL VBO. his sucessive .Add calls are equivlent to your glvertex3f + gltexcoord2f calls, pos would be the sprite position on the map, w/h are the size of the quad that is rendered (note that he's actually creating two triangles here to make a quad.

    but without knowing how his w+h are calculated and how the texEntry U1,V1,U2,V2 values are created, I can't give you any more information.

    I've looked up on GTA files and rendering, I've found :

    http://brain.wireos.com/?p=1673

    A GTA 2 .Sty parser (and looking at that, are you parsing .sty files or have you converted them to textures you're using?)

    and

    http://gtamp.com/gta2/tools/

    which contains a link to gta1-gta2-tool-source-code.7z released by jernej, inside that archive there's tons of code dealing with GTA1 and 2 data files.

    I can't be certain without extensive study, but his STY editor does seem to suggest that there's additional offset information that comes with each sprite defintion.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  5. #5
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Only just saw your Edit, brilliant I'm really happy that I could of helped but feel free to post any further questions you might have and I'll do my best.

    And I also know why there's black borders, there's additional animations for sprites, like car doors opening etc and if you were to go thru all the images (such as a ped walking) you'd probably see that all the pixels get used eventually across all the frames of animation etc

    because animations must be stored in an array of images of exact dimensions, you'll have some frames that don't seem centred etc
    Last edited by phibermon; 31-03-2013 at 04:13 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  6. #6
    The brain.wireos sty reader is the one i use because he wrote this for me. And the code is so fast.

    And thanks to this im able to render these sprites and stuff. But yes for emergency lights on cars etc, its a bit complicated but nothing impossible i guess. Atm i just want to render sprites/game objects on map.

    But npot textures scared me. But now it seems OK.

    Btw, just for the info, from the STY docs:

    "5.1 Sprite Graphics Data
    Sprites are stored as uncompressed 256-colour graphics upto 32 pages of 64K each. Each page is 256x256 pixels. The maximum size of a sprite is 128x64 and the minimum is 2x2. The width and height can have any value inbetween as long it is an even number."

  7. #7
    I know you are still using bit of your own texture loading, but i'll still give short example how nxPascal would do NPOT. You can download Delphi source and exe here. I made it as simple as possible but based on the game template:
    https://docs.google.com/file/d/0B7FI...NlYWRvLW8/edit

    There is no scaling of any kind, demo loads in 119x53 texture with 12 patterns in 6x2 grid. There is SkipWidth and Height of 1 because i drew it quickly with a green 1 pixel wide grid, which i had to take off because bi-linear rendering makes the grid show when drawn.

    To summarize key points:
    Code:
    n:=tex.AddTexture('anim', GetPath('textures\anim.png'), true);
    tex.SetPattern(n, 19, 26, 1, 1);
    ...
    pattern:=(pattern+1) mod 12;
    nx.DrawRotate((i mod 30)*15.0+20, (i div 30)*15.0+20, pattern, 0, 0.5, 0.5);
    // I drew 1000 of these patterns, 30 per row, each centered around coords 0.5, 0.5 of the pattern, that's exactly in the middle.
    Attached Images Attached Images

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
  •