13 Replies - 3227 Views - Last Post: 26 January 2013 - 07:15 AM Rate Topic: -----

#1 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Draw rectangle with DirectX?

Posted 24 January 2013 - 08:16 AM

Alright, so I've been teaching myself programming, mainly for game development. I started off small, learning javascript and python, but later jumped over to software-based languages such as c++ and DirectX.

Now, I learn by looking at code, because I'm a visual learner. I look at the code, dissect it, and if I don't understand a symbol, or the reason why something was written, I look it up. I've been doing fairy good up until now, DirectX seems to make C++ very complicated, but then again, I'm self-taught.

What I was hoping to find out from you guys is this, suppose I wanted to learn about the Direct2D method of using sprites. I want to see how a rectangle would be drawn using the Direct2D API, and if I have to use a texture, or can I just use a solid color for learning purposes.

I have a fairly good understanding of C++, but trying to learn DirectX has thrown me through a loop. I have no idea how to go about drawing anything in a win32 program, I was able to create the actual window, but I haven't been able to find anything online in terms of creating a simple shape.

Could somebody please help me with this? Or at least point me in the right direction. I'm thinking of going to college for this, but if I can't figure out something as simple as this, I may not waste my time.

Thank you and I look forward to your response.

This post has been edited by N1ghtm4r3: 24 January 2013 - 08:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Draw rectangle with DirectX?

#2 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 08:31 AM

By the way, I found this site that I am using as a main reference, he does a fairly good job at showing examples and describing why everything works the way it does. This link is to the section on how to create just a simple window, but his next example is how to use sprites to draw a triangle. I'm having trouble following this part, as it seems rather complicated to draw a simple triangle.

DirectX Tutorial
Was This Post Helpful? 0
  • +
  • -

#3 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 08:49 AM

Also, I guess I should ask, is this the correct area for this type of question?

I just assumed because it is C++, but if there is a better spot to ask a question relating to DirectX, can somebody let me know, thanks.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 10:48 AM

I'm on my iPhone so can't move this to the game development section. Someone should to that soon, so don't worry.

Regarding your question and concerns, if you are really having problems with the tutorials you've linked to you really need to brush up on your C++. Granted that DirectX is challenging to get your head round when you are new to it, but you are getting stuck early.

I wouldn't be looking at games quite yet in your shoes. Become a strong C++ programmer first.
Was This Post Helpful? 0
  • +
  • -

#5 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 10:54 AM

View PostButchDean, on 24 January 2013 - 10:48 AM, said:

I'm on my iPhone so can't move this to the game development section. Someone should to that soon, so don't worry.

Regarding your question and concerns, if you are really having problems with the tutorials you've linked to you really need to brush up on your C++. Granted that DirectX is challenging to get your head round when you are new to it, but you are getting stuck early.

I wouldn't be looking at games quite yet in your shoes. Become a strong C++ programmer first.


Well, thanks a lot for the info and the response.

I do have a pretty firm grasp of C++, it's just that the tutorial is showing a whole lot of parameters that I don't recognize. I understand they're for DirectX, prewritten functions that make it easier to get stuff accomplished. I'm just not sure how I could apply this to creating something as simple as a rectangle.

I appreciate your advice, but I'm bound and determined to learn DirectX. I've already created a tetris game, as well as a few other simple games in the console. So, now I want to get into the graphical aspect of it all. I have also dabbled in XNA, but that was very little, a long time ago.

Hopefully, someone will be generous enough to walk me through this. I feel that if I can figure out how to do this, I can piece the rest together.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1368
  • View blog
  • Posts: 4,737
  • Joined: 19-February 09

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 11:34 AM

There is quite a lot to WinAPI (which includes DirectX) so it is easy to be daunted. You don't need to know it all though.

Wikipedia gives an overview - Windows API

Here is a good basic tutorial on WinApi - Windows API tutorial
Was This Post Helpful? 0
  • +
  • -

#7 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 01:51 PM

View Post#define, on 24 January 2013 - 11:34 AM, said:

There is quite a lot to WinAPI (which includes DirectX) so it is easy to be daunted. You don't need to know it all though.

Wikipedia gives an overview - Windows API

Here is a good basic tutorial on WinApi - Windows API tutorial


Thanks a lot for the links, I have bookmarked them.

However, I was still hoping somebody would be willing to give me a bare-minimum example of how I could create a simple rectangle, or square. I understand you use triangles to create them, unless using a buffer, correct? If I could get an example of that, it would help me to understand why and how it is done. Like I said, I'm a visual learner, so I have to see the code and know what it does, so I can dissect it for myself.

I would usually just search for what I need and look at the example to learn, however, I can't find anything as simple as this anywhere, they jump right to using textures and buffers to accomplish a finished look. I'm juts looking for the most simplistic method, then I can build from there.

Thank you everybody!
Was This Post Helpful? 0
  • +
  • -

#8 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 03:21 PM

Sorry, double post.

This post has been edited by N1ghtm4r3: 24 January 2013 - 03:22 PM

Was This Post Helpful? 0
  • +
  • -

#9 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 07:03 PM

Nobody?
Was This Post Helpful? 0
  • +
  • -

#10 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1368
  • View blog
  • Posts: 4,737
  • Joined: 19-February 09

Re: Draw rectangle with DirectX?

Posted 24 January 2013 - 07:42 PM

I'm not sure there is a very simple tutorial.

Also there is different ways of displaying a rectangle.

It can be 2D or 3D.

Drawing with Direct2D

Talk:DirectX:DirectDraw:Tutorials:VB:DX7:Efficient Line Drawing and Text Display


Wikipedia : 3D computer graphics

There is a DirectX 9 version of your triangle tutorial
Lesson 4: Drawing a Triangle


A sprite could be used to draw a rectangle.
2D Scrolling with DirectX

Rectangle here it looks like.
D3D9 Help


I think is hoping to move this to game development, so you might get better help there eventually.
Was This Post Helpful? 1
  • +
  • -

#11 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 25 January 2013 - 06:51 AM

Well, thank you very much for the links, I'll skim through those and let you know if I can manage with them. I guess I thought it'd be a fairly simple sample of code, but I guess I was wrong.

DirectX is a bit more complicated than I imagined. Hopefully, someone in game programming can whip up something for me, if not, maybe I can get by on your links.

Thank you for all your help #define!

This post has been edited by N1ghtm4r3: 25 January 2013 - 06:52 AM

Was This Post Helpful? 0
  • +
  • -

#12 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1368
  • View blog
  • Posts: 4,737
  • Joined: 19-February 09

Re: Draw rectangle with DirectX?

Posted 25 January 2013 - 03:31 PM

Having looked at the tutorial, to change it from a triangle to a rectangle, I would try adding another point to the vertex buffer and change how they are drawn (DrawPrimitive).

With DrawPrimitive you can try using D3DPT_LINESTRIP (this is an option of how to draw it), and change the number of primitives to 4.

I think snoopy11 did a tutorial on the primitive types but I haven't found it yet.
Was This Post Helpful? 0
  • +
  • -

#13 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 25 January 2013 - 04:01 PM

View Post#define, on 25 January 2013 - 03:31 PM, said:

Having looked at the tutorial, to change it from a triangle to a rectangle, I would try adding another point to the vertex buffer and change how they are drawn (DrawPrimitive).

With DrawPrimitive you can try using D3DPT_LINESTRIP (this is an option of how to draw it), and change the number of primitives to 4.

I think snoopy11 did a tutorial on the primitive types but I haven't found it yet.


Awesome. Thank you!

I've been reading all day today, working my head around all of this. I think I'm starting to catch on, but there is so much to it.

I can barely keep my eyes open now, but I'll be back tomorrow.

Thank you so much for your support.
Was This Post Helpful? 1
  • +
  • -

#14 N1ghtm4r3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-May 11

Re: Draw rectangle with DirectX?

Posted 26 January 2013 - 07:15 AM

I couldn't fins Snoopys tutorial either.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1