How do I draw Primitive Shapes using C++
I'm trying to learn how to draw graphics with C++, and so far I've only started to learn D3D. But in D3D, you can only draw triangles (as it seems to me).
So how do people usually draw their circles/rectangles/lines in a simple way?
i.e. What's the most simplest way to draw a primitive shape?
The most simple way is actually through an API.
Direct3D can only draw primitives? Ummm...where did you hear that? D3D can load up models and more. Direct3D is a very powerfull graphics API.
You can also use OpenGL. I would say it is simpler, but some people think D3D is as simple. I am actually one of those people even though I use OpenGL right now. I use OpenGL as to me it teaches me at a lower level, which seems to be very important in computer science.
Some DirectX Tutorials can be found here: "Chad's (not me) DirectX tutorials."
Chad.
Direct3D can only draw primitives? Ummm...where did you hear that? D3D can load up models and more. Direct3D is a very powerfull graphics API.
You can also use OpenGL. I would say it is simpler, but some people think D3D is as simple. I am actually one of those people even though I use OpenGL right now. I use OpenGL as to me it teaches me at a lower level, which seems to be very important in computer science.
Some DirectX Tutorials can be found here: "Chad's (not me) DirectX tutorials."
Chad.
I meant the basic way, not having to download additional SDK.
Since I'm a beginner, I'd be more interested in drawing simple black and white rectangles rather than creating complicated stuff with OpenGL / D3D.
Since I'm a beginner, I'd be more interested in drawing simple black and white rectangles rather than creating complicated stuff with OpenGL / D3D.
Since I doubt that you want to use the console window to draw stuff (which is the only way to draw shapes using ONLY C++ - no graphical API), you need Direct3D / OpenGL (or any other suitable graphical API) to draw primitives.
Here's an example that draws a yellow rectangle in OpenGL that measures 50 x 50 pixels (assuming you've set it up already)...
There are plenty of tutorials on the net that can help you get started...
NeHe - OpenGL Tutorials just to name one such site.
Here's an example that draws a yellow rectangle in OpenGL that measures 50 x 50 pixels (assuming you've set it up already)...
glBegin(GL_QUADS); // Begin drawingglColor3ub(255, 255, 0); // Change color to bright yellowglVertex2i(50, 0); // Top-right cornerglVertex2i(0, 0); // Top-left cornerglVertex2i(0, 50); // Bottom-left cornerglVertex2i(50, 50); // Bottom-right cornerglEnd(); // Finish drawingThere are plenty of tutorials on the net that can help you get started...
NeHe - OpenGL Tutorials just to name one such site.
Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.
SDL
http://www.libsdl.org/index.php
Recommend this for learning SDL.
http://lazyfooproductions.com/SDL_tutorials/index.php
This has a chapter on how to draw primitives with SDL
http://sol.gfxile.net/gp/index.html
SDL
http://www.libsdl.org/index.php
Recommend this for learning SDL.
http://lazyfooproductions.com/SDL_tutorials/index.php
This has a chapter on how to draw primitives with SDL
http://sol.gfxile.net/gp/index.html
SDL, too, is a Graphic API.
I second SDL, though. It's simple yet elegantly powerful. However, it's not intended for 3D. Oh, and I further second LazyFoo's tutorial. But if the OP is using D3D, shouldn't we be offering help pertaining to his question, rather than suggest alternative APIs? I haven't used Direct3D, however, so I can't be of help.
I second SDL, though. It's simple yet elegantly powerful. However, it's not intended for 3D. Oh, and I further second LazyFoo's tutorial. But if the OP is using D3D, shouldn't we be offering help pertaining to his question, rather than suggest alternative APIs? I haven't used Direct3D, however, so I can't be of help.
Quote:Original post by Servant of the Lord
SDL, too, is a Graphic API.
I second SDL, though. It's simple yet elegantly powerful. However, it's not intended for 3D. Oh, and I further second LazyFoo's tutorial. But if the OP is using D3D, shouldn't we be offering help pertaining to his question, rather than suggest alternative APIs? I haven't used Direct3D, however, so I can't be of help.
I too don't know D3D, but it seemed to me that learning SDL would be much easier and more rewarding for a beginner than struggling with D3D. Also, SDL has a use in the long run as a base for OGL and writing quick demo apps.
yes, you are going to have to use a Graphics API. C++ does not provide any GUI support. Although the creator would like to have it in there.
If you are ready to go into graphics then I suggest SDL actually. Actually...not that I think about it. I don't suggest anything anymore. I am not going to lie. I used SDL also...but then once I got into the real Win32, DirectX, and OpenGL world, I felt babied with SDL. Now...Win32 programming can be confusing, but it just takes time, then you will understand it.
if you compare the GL and DX code for drawing a primitive, then you will see that GL does require less code although some poeple seem to like how DX does stuff with it. It is totally up to you though. Just take time and look at all the API's, and try them out, and think about which one you want to spend time with, and learn graphics with. SDL is VERY VERY simple to use, although I did feel babied when I entered the Win32 world, which is something you basically can't hide.
Another API that no one has suggested right now is Allegro. I have never used it, but I have herd good things on it. Might want to google it.
I hope any of this information has helped ya!
Chad
If you are ready to go into graphics then I suggest SDL actually. Actually...not that I think about it. I don't suggest anything anymore. I am not going to lie. I used SDL also...but then once I got into the real Win32, DirectX, and OpenGL world, I felt babied with SDL. Now...Win32 programming can be confusing, but it just takes time, then you will understand it.
if you compare the GL and DX code for drawing a primitive, then you will see that GL does require less code although some poeple seem to like how DX does stuff with it. It is totally up to you though. Just take time and look at all the API's, and try them out, and think about which one you want to spend time with, and learn graphics with. SDL is VERY VERY simple to use, although I did feel babied when I entered the Win32 world, which is something you basically can't hide.
Another API that no one has suggested right now is Allegro. I have never used it, but I have herd good things on it. Might want to google it.
I hope any of this information has helped ya!
Chad
ok, since people started talking about some better-level libraries, I might as well be more direct.
I want a simple starter program where I could draw boxes and circles. I don't wanna mess around with other technologies for now, coz I'll have to load the device, render, etc (too hard for me to memorize).
How do I create those shapes in a win32 window? I think it has something to do with the WM_PAINT event.
I want a simple starter program where I could draw boxes and circles. I don't wanna mess around with other technologies for now, coz I'll have to load the device, render, etc (too hard for me to memorize).
How do I create those shapes in a win32 window? I think it has something to do with the WM_PAINT event.
Quote:Original post by dadads
ok, since people started talking about some better-level libraries, I might as well be more direct.
I want a simple starter program where I could draw boxes and circles. I don't wanna mess around with other technologies for now, coz I'll have to load the device, render, etc (too hard for me to memorize).
How do I create those shapes in a win32 window? I think it has something to do with the WM_PAINT event.
Well to draw to a a window using win32 api, you will need to set up the window first.
Considering this, SDL offers an even easier solution to set up a window and draw to it.
Also you don't need to memorize most of the code a tutorial offers you, all you should try is to understand it.
Share:
This topic is closed to new replies.
Advertisement
Advertisement
