C#-APP:Title Screen in DirectX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fromethius
    New Member
    • Apr 2007
    • 38

    C#-APP:Title Screen in DirectX

    I have been looking for hours for something like this without using the deprecated DirectDraw. I'm looking to use DX9 with either VB .Net or C# code. I would prefer C# but VB .Net code is fine.

    I already have my main form with all the graphics and such draw on it. However, it would be great if I could make a TitleScreen sort of thing. I am using fullscreen mode, by the way.

    Anyways, the TitleScreen would come up first in full screen mode and in the middle of the screen it would say, "Press enter to start the game". And then when you press Enter on the Keyboard, the main form would come up with all those graphics drawn on it I stated previously.

    Thanks for any help given whatsoever!
  • Fromethius
    New Member
    • Apr 2007
    • 38

    #2
    Oh, btw, I am using 2005.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Title screens are not usually processor or graphically intensive, therefor you could probably get away with using GDI to draw a bitmap to the screen.

      Comment

      • Fromethius
        New Member
        • Apr 2007
        • 38

        #4
        Well, I was hoping I could operate it on a different form. This is because that I will also have an options option, about option, play game option. Here I'll draw up an example real quick in Paint.



        See, I can handle drawing to the screen. Such that when you press the down arrow key, it draws a triangle to the options menu. Up goes back up to play game.. etc.

        Btw, I'm not using this bitmap, this is just an example to what I'm drawing to the screen. I would just like an idea on HOW to draw it to the screen. I'm thinking something like making a TitleScreen Form, and then on startup, load the form instead of my main form. But now, since it is a diferent form. Don't I have to repeat all of my coding such as declaring and initializing Devices, PresentParamete rs, etc?

        And also there would be an options form, credits form, etc. How can I switch between forms and such? Also, if I load up my TitleScreenForm first, don't I need to declare a backbuffer and such, and when I click Play Game, do I dispose of that buffer and then create a new one? Won't that make a flicker of some sort? Is there an easier way to switch back and forth using clean code and not redundance?

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          I really think that for something as simple as a title screen, you can get away with all your drawing relying on GDI's built in shape and font functions.

          Comment

          • Fromethius
            New Member
            • Apr 2007
            • 38

            #6
            Well, I also want it in full-screen mode. And not that form border style.. black background fullscreen. Also, in the future I may want to change the TitleScreen to something for advanced. But uhh.. If let's say you have a full screen with directx, can you still draw onto it with GDI+? If so, how? Just the regular Paint method?

            Also, how can I transition the forms so that when you go from the TitleScreen to the main game, it is smooth. Like.. Would I just dispose the TitleScreen and show the main form? That would be a bit messy wouldn't it?

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              I am not horribly experienced with GDI, however, you should be able to get a DC for your window, create a pen and brush, then paint to the screen. You should be able to do this on top of whatever else you are rendering in DirectX as well. The GDI functions are slow, but it shouldn't be a problem as you wont have to redraw often.


              Originally posted by Fromethius
              Well, I also want it in full-screen mode. And not that form border style.. black background fullscreen. Also, in the future I may want to change the TitleScreen to something for advanced. But uhh.. If let's say you have a full screen with directx, can you still draw onto it with GDI+? If so, how? Just the regular Paint method?

              Also, how can I transition the forms so that when you go from the TitleScreen to the main game, it is smooth. Like.. Would I just dispose the TitleScreen and show the main form? That would be a bit messy wouldn't it?

              Comment

              • Fromethius
                New Member
                • Apr 2007
                • 38

                #8
                =/

                OK. How about this? Is there a way to share variables across all forms? Like.. all forms inherit all the PresentParamete rs properties, the device, etc.

                Code:
                            PresentParameters presentParams = null;
                            Device device = null;
                            DisplayMode displayMode;
                
                            displayMode = Manager.Adapters[0].CurrentDisplayMode;
                
                            presentParams = new PresentParameters();
                            presentParams.DeviceWindow = this;
                            presentParams.Windowed = false;
                            presentParams.SwapEffect = SwapEffect.Discard;
                            presentParams.BackBufferWidth = displayMode.Width;
                            presentParams.BackBufferHeight = displayMode.Height;
                            presentParams.BackBufferFormat = displayMode.Format;
                You know what? Come to think of it. That is not a lot of code that needs to be shared. But still, is there a way to share that code among all my forms, easily?

                Would I just make them all static and then every form could just pull them off of one form?

                Thanks

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  If you make your functions static, you cannot access the 'this' pointer in any of them.
                  The best way to do this would be to create a class with those properties, and give each form a pointer to that class.

                  Comment

                  • Fromethius
                    New Member
                    • Apr 2007
                    • 38

                    #10
                    Alright. I will try this out

                    Comment

                    • Motoma
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3236

                      #11
                      Originally posted by Fromethius
                      Alright. I will try this out
                      Yeah, post back and let me know how everything works out for you. Good luck, and welcome to theScripts.

                      Comment

                      • Fromethius
                        New Member
                        • Apr 2007
                        • 38

                        #12
                        Originally posted by Motoma
                        Yeah, post back and let me know how everything works out for you. Good luck, and welcome to theScripts.
                        Heh. Thanks. I'm still trying to fiqure it out. If I have PresentParamete rs declared on Form1 and Form2. I want to initialize them the same way for both forms. So yea, use a class that both forms have access to. However.. I can't quite seem to get it work. I'm trying something like this but I know it isn't working. Tell me if you have any ideas:

                        Code:
                            class GlobalProps
                            {
                                void InitializeGlobalProperties(System.Windows.Forms.Control sender)
                                {
                                    sender.displayMode = Manager.Adapters[0].CurrentDisplayMode;
                        
                                    sender.presentParams = new PresentParameters();
                                    sender.presentParams.DeviceWindow = sender;
                                    sender.presentParams.Windowed = false;
                                    sender.presentParams.SwapEffect = SwapEffect.Discard;
                                    sender.presentParams.BackBufferWidth = displayMode.Width;
                                    sender.presentParams.BackBufferHeight = displayMode.Height;
                                    sender.presentParams.BackBufferFormat = displayMode.Format;
                        
                                    sender.device = new Device(0, DeviceType.Hardware, sender, CreateFlags.SoftwareVertexProcessing, presentParams);
                                }
                            }
                        See, since it is sender, at design mode, it doesn't know if presentParams is there, so it won't let me compile. Any ideas?

                        Comment

                        • Motoma
                          Recognized Expert Specialist
                          • Jan 2007
                          • 3236

                          #13
                          What error messages are you getting? You may want to make InitializeGloba lProperties be a public function.

                          Comment

                          • Fromethius
                            New Member
                            • Apr 2007
                            • 38

                            #14
                            Well.. presentParams is only declared in Form1. So when I make a class in a seperate file, it says, wtf is presentParams and doesn't compile. There will be like 4 Forms that all have presentParams declared on it. So, I want to be able to just type in:

                            Code:
                            GlobalParams globalParams = new GlobalParams();
                            globalParams.InitalizeParams(this);
                            Then, it will do the BackBufferWidth and Height settings, the SwapEffect, etc. on that form.

                            Comment

                            • Motoma
                              Recognized Expert Specialist
                              • Jan 2007
                              • 3236

                              #15
                              When you put the class in a separate file, you are going to have to declare the namespace through the "using" keyword.

                              Comment

                              Working...