Results 1 to 13 of 13

Thread: 2d Textures

  1. #1

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    2d Textures

    I have a question regarding DirectX 8. I’m basically trying to draw a 2d pipe at any angle. Right now I can do it, but in a very slow way. I’m using a 20*24 bitmap for my pipe texture and I make a bunch of little 20*24 sets of vertices. So that means when I draw a pipe from (0, 20) to (500, 20) 25 polygons are created and there are 25 drawing operations. Is there a way that I can just have one polygon consisting of 4 vertices and have the texture draw properly? (by the way, the pipe texture is such that stretching it would completely mess it up the look). Hopefully someone knows how to do it because when I have a mere 50 pipes the fps plummets.
    Hooked for good.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: 2d Textures

    Could you post you pipe-drawing code?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    Sure thing, here it is.
    Attached Files Attached Files
    Hooked for good.

  4. #4

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    Not many pipes are being drawn in that example but you can change it by changing the constant called "Up". If you set the amount of pipes to 50 or some higher number the fps will take a hit.
    Hooked for good.

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: 2d Textures

    Instead of drawing 100 vertex lists, try creating new polygons for every new random pipe and then draw just using one vertex list within your for loop. That's probably whats bogging it down.

  6. #6

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    How would I go about drawing with one per pipe in my loop? Do you mean that it would be faster to make the vertexes during the loop?
    Hooked for good.

  7. #7

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    Ok, I've made it so that the polygons are created in the game loop and it's faster than before but still not that fast. Before it was about 30fps on my pc and now it's 45fps - on 50 pipes! I'm hoping to get hundreds of these pipes because a lot of them will be visible when i zoom out in my program. My new code is much nicer than the other was. Here it is.
    Attached Files Attached Files
    Hooked for good.

  8. #8
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: 2d Textures

    I messed around with it and made it faster. I eliminated the Form_Activate (God knows why I used that a lot back then) and put it in Form_Load. And after extensive messing around, I get upto 60 FPS with it now and I added clipping. Only draw what you see! Drawing offscreen is a waste. Also fullscreening it made it even faster, and i eliminated the picturebox and timer. I'm now using real time to measure FPS. Timers are screwed up on Windows 7 for some reason and jump 10 times faster than normal. So it had to go. The time code I added is much better. Also I havent messed with it in awhile but maybe doing an advanced technique such as locking the screen surface pointer, then running the for loops, then unlocking it might make it even faster. Its gonna be kinda bogged no matter what cause you are using multiple polys and textures for each pipe anyways. And multiplying that by 200-300 times lets say an average 20 textures each, it adds up. So the loop needs to process 4000-6000 iterations per loop. For what you have its not bad. And its always open for more optimization.

    [EDIT] Change the Borderstyle to none cause it gets iffy around the edge when moving the mouse around. Personally I'd be using DirectInput for the keyboard and mouse stuff but you're still learning lol.
    Attached Images Attached Images  
    Attached Files Attached Files

  9. #9

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    The program runs quite well right now when the pipes are that big. What i'm trying to do is this: i'm making a program which is a hydrolic designer program with the interface of a game. At first i used GDI and got it working quite well but it just wasn't fast enough. Bitblt could draw very fast but took a lot of memory. Now I'm really stuck and need some help because this needs to be so fast that 500 pipes will be able to be drawn at once (when zoomed out a lot will be visible). Another thing that is against me is that i do need to draw it in a picturebox, not full screen because of the kind of program.

    Mission impossible? I don't know but i'll see if somebody knows how to get DirectX to perform - big time.
    Thanks for all your help.
    Hooked for good.

  10. #10

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    It seems such a shame to have do make about 20 polygons for each pipe. I did an experiment where it was just one polygon for the pipe and the texture stretched. It was drawing 2000 pipes at 30fps!!! One option would be a texture change but could there be a way of getting DX to tile the texture instead of stretch it? That would be the perfect soulution - nice looking pipes which are blazingly fast.

    This is 2000 pipes with stretched textures:
    Attached Images Attached Images  
    Last edited by cheesebrother; Nov 1st, 2011 at 02:41 AM. Reason: Added picture
    Hooked for good.

  11. #11
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: 2d Textures

    Theres not gonna be any sense of drawning 1000s of pipes on top of each other cause then youd be overlapping other pipes thus whatever got drawn behind the other pipes was a wasted drawing routine cause then you cant see em, so you end up with 100s of wasted drawing cycles per frame. If what you have is fast enough without stretching the texture, then work with what you have. After all it is a hydraulic designer for a game, not a mish mash of pipes lol

  12. #12

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    Yes, my test prog was quite chaotic. I'll stretch the texture where i can and make polygons where i have to. Thanks a lot for your help.
    Hooked for good.

  13. #13

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: 2d Textures

    In the "NewImprovedPipes" example text was drawn to display the fps. Now that i've got drawing the actual pipes unde control i'd like to draw a caption beside each of them. How can i draw rotated text?
    Hooked for good.

Posting Permissions

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



Click Here to Expand Forum to Full Width