c++ print shapes in the console (cmd) [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I’m building a maze game in C++ and I’m trying to use shapes to identify characters in the game i.e. walls as squares, triangles as enemies and a star shape as the player. How can I print such elements in the console cmd? I have been researching a lot on http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx but I’m not able to figure it out.
If there isn’t a way then is it possible to print an svg?

There are several solutions to this problem, each with its own drawbacks and advantages.
Emoji (or more precisely Unicode)
This is my recommendation for simple games and shapes as it is the most simple to implement and relies on the underlying console to do the heavy lifting. Also how the other program was most likely written (though with other characters than listed here)
Since the windows terminal (and linux/macOS) supports Unicode, it is possible to use unicode characters such as 🔲, ⭐, and 🔺 to represent characters.
Note: you may need to enable utf8 support with setlocale(LC_ALL, "en_US.utf8"); in cpp
Pros
Simple to implement
Doesn't rely on external libraries
Cons
Confined to the standard text alignment
Hard to resize
Need to clear characters manually
What happens if the console is resized or too small?
ConPTY
Similar to the console approach, though this gives the advantage of more colors and the capability to set console size, etc. by the program.
Pros
Color support
Ability to control the terminal more simply
Cons
Still need to choose another method to actually print
Requires Windows 10
Console
This is takes control of the console windows. You should use a library such as https://github.com/Bill-Gray/PDCursesMod to abstract this method.
Pros
Capable of full control without leaving the terminal
Less resource intensive than a full window
Cons
Complex
Windows
You can use frameworks such as Qt and co to implement a window environment. This approach gives the most flexibility, though at the cost of complexity, with at least a couple months of development time (from scratch), though this issue can be overlooked with the proper framework/library.
Pros
More common nowadays
Most control
A number of libraries are available for games already.
Cons
Most resource intensive
Hardest to implement from scratch
Not terminal based (though you can make it seem as though it is)

Related

How to display graphics on a C++ program without third party libraries? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I can't seem to find the answer I'm looking for, or I might miss understand this. Either way I am confused.
When I try to find out, there is always videos about C++ console programming, which annoys me because I wanna move away from console stuff by now. I know how to create a simple window, but not how to display real graphics on it. I have heard of stuff like OpenGL and DirectX, but it makes me wonder, what do those libraries have in their source whcih draws actual shapes and other things on the program? What C++ functions do they use in their code?
Well, you could make your own graphics library. In that case I suggest you grab a good math book, and get ready to do some rather serious maths. You'd also have to get going and start right now to learn about Windows graphics drivers and Windows Kernel development, or about the X11 API and Linux Kernel programming, or all of those. The documentation is available on the Net.
What OpenGL and other graphics libraries do is provide a relatively simple API so you don't have to reinvent the wheel, and make your own library which would take years before having anything close to what they provide.
Don't get me wrong, even with these nice API's, there is much room for doing 'magic'. Computer graphics are an art in and of themselves. Mastering some of the techniques offered by the libraries require a good knowledge of the maths involved, and of the possibilities offered by the hardware as well.
But, like everything, it can be learnt. If you are interested in doing graphics on a computer, you should start by finding a good source on the subject, there are many online. And start playing with the APIs. OpenGL is a good place to start, but there are also open source libraries that build on that, since drawing polygons ans stuff involves many other aspects of computing. Ogre3d comes to mind, but there are also others.
Briefly, what graphics APIs have in their source is interaction with the graphics hardware, and telling it to write pixel values in memory. Ultimately this is usually done in an indirect way, such as setting up a scene graph, and and graphics APIs provide an interface to work with low level hardware systems.

How can I add a GUI to my homework? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am currently taking Intro C++ in my college. This was a very simple homework which I had to program using 3 different methods to output "1 2 3 4". Being ahead of my current skills, how can I add visual interfaces to this program that I just wrote? I mean, I want to change colors, add buttons or picture or whatever. Is that possible?
//Jaehyuk Oh
//Professor Kan, Shaobai
// 2/9/2014
// HWK. 2.17
// (Printing) Write a program that prints the numbers 1 to 4 on the same line with each pair of adjacent numbers separated bt one space. Do this several ways:
// a) using one statement with one stream insertion operation.
// b) using one statement with four stream insertion operators.
// c) using four statements.
#include <iostream>
int main()
{
std::cout<<"1 2 3 4\n"; // ------> a)
std::cout<<"1 "<<"2 "<<"3 "<<"4\n"; // ------> b)
std::cout<<"1 "; // ----------> c)
std::cout<<"2 ";
std::cout<<"3 ";
std::cout<<"4"<<std::endl;
system("PAUSE");
return 0;
}
C++, as a language, has no idea of what is a color or a button.
The standard input is just a stream of characters and the standard output is a stream of characters. Nothing fancy.
There are environments in which you can control a few the visual aspects (like the color of text) using just special control characters, "escape sequences", but they work only if you run the program in a terminal that supports these (e.g. a Linux terminal).
Running the program in an environment where these escape sequences are not interpreted would just confuse the output (e.g. in a Windows console).
I'll start by saying that you should only turn into your instructor what is expected of you, and nothing more. For example, if you use a GUI, you might end up implementing your above code in such a way that you don't use stream insertions. Since that is the whole point of the assignment, your professor might give you a 0 for not using stream insertions, regardless of whether you can do something more complex or not.
However, as a project in your free-time, you can look into WinForms. WinForms is a library in .Net that has many GUI elements built into it - such as buttons and various text views, and it is built in C++. As one commenter said, this is a broad question, but WinForms is a fairly easy-to-use API for GUIs in C++, so it's probably the most natural option to use, especially if you already have a Visual Studio compiler.
Since you have vs2010 express tagged, it sounds like you're set to give it a shot.
Writing GUIs can take a while to get used to, so don't be discouraged if you don't 'get it' immediately. There are good reasons why GUI programming isn't a typical intro to programming topic.
Good luck!

What are the advantages of extending Python with C or C++? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Recently I've read that we can code C/C++ and from python call those modules, I know that C/C++ is fast and strongly typed and those things but what advantages I got if I code some module and then call it from python? in what case/scenario/context it would be nice to implement this?
Thanks in advance.
Performance. That's why NumPy is so fast ("The NumPy array: a structure for efficient
numerical computation")
If you need to access a system library that doesn't have a wrapper
in python (Example: Shapely wraps around libgeos to do
geometrical computations), or if you're writing a wrapper around a
system library.
If you have a performance bottleneck in a function
that needs to be made a lot faster (and can benefit from using C).
Like Charlie said, profiling is essential to find out whether you
want to do this or not.
Profile your application. If it really is spending time in a couple of places that you can recode in C consider doing so. Don't do this unless profiling tells you you really need to.
Another reason is there might be a C/C++ library with functionality not available in python. You might write a python extension in C/C++ so that you can access/use that C/C++ library.
The primary advantage I see is speed. That's the price paid for the generality and flexibility of a dynamic language like Python. The execution model of the language doesn't match the execution model of the processor, by a wide margin, so there must be a translation layer someplace at runtime.
There are significant sections of work in many applications that can be encapsulated as strongly-typed functions. FFTs, convolutions, matrix operations and other types of array processing are good examples where a tightly-coded compiled loop can outperform a pure Python solution more than enough to pay for the runtime data copying and "environment switching" overhead.
There is also the case for "C as a portable assembler" to gain access to hardware functions for accelerating these functions. The Python library may have a high-level interface that depends on driver code that's not available widely enough to be part of the Python execution model. Multimedia hardware for video and audio processing, and array processing instructions on the CPU or GPU are examples.
The costs for a custom hybrid solution are in development and maintenance. There is added complexity in design, coding, building, debugging and deployment of the application. You also need expertise on-staff for two different programming languages.

What good options exist for effectively managing Eclipse/CDT build configurations? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
We are aiming to leverage software reuse in embedded ARM/Linux platforms. Some of our hardware platforms are designed for customers' specific needs. Of course the application would be customized in various ways too.
While it is not an Android product, for one it is way too big compared to ours, it does make a good analogy in that other than the constant of being Linux based, there are different look and feel to the UI, there are different phones, there are different CPUs, there are different firmwares for different radios, etc. So there are many configurations to manage. And the configurations are a sparse matrix, in that not all combinations exist.
Continuous Integration is also not completely out of the picture in the future.
So for the near future the end point seems to be:
A core set of libraries that we want to keep developing and apply everywhere. Class inheritance supplies the customizations. So there is a build configuration for the application types.
A handful of customized ARM/Linux hardware platforms. Seems a BSP/board class HAL for our libraries is the way to go. That means a build configuration to pick the right hardware/board.
A handful of co-processor firmwares matching to the hardware/board, but the API to our libraries is the same. So there is a build configuration depending on the firmwares.
A handful of implementation for different look and feel/applications. That's another build configuration.
Needless to say there are many include paths, #define's, and file exclusions to make all these work.
So as you can see, if we wanted a collection of Eclipse/CDT projects in a workspace that allows us to build all these variants in the same environment all at once, there are a lot of configurations to create and manage in Eclipse/CDT. If the GUI is the only way to manage, there is a whole deal of mouse clicking to do. And after that there is no simple way to verify that all configurations are setup correctly without a whole lot more mouse clicking. There isn't a dashboard view. Is there a text editor based approach to manage all these?
I did try to do my homework. I understand that there is the 'Import Settings...' and 'Export Settings...' buttons in the 'Paths and Symbols' tab. But it does one configuration at a time, for one project at a time. It doesn't seem very systematic and is easy to miss something.
I have also look directly at .cprojects but I worry that if I made a mistake Eclipse will just silently do the unexpected things and will take big effort to fix.
Do fellow experts have a better suggestion?

What counts towards demo scene size restrictions? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
So I wanna make a small (64k) demo--nothing super impressive, just for the coding experience. I've been wondering, what exactly counts towards a byte count? For example, I could embed Lua as a scripting language once I have a simple demo engine running, but since python comes on pretty much every *nix computer, can I use its interpreter at no cost?
Some might argue that it's not in the spirit of the demo scene, but I do think it counts as milking every last byte. Plus, Lua is 50k and I don't want to write a smaller, custom interpreter (which will be buggy).
The general spirit of the thing is that, as a piece of art, any random person ought to be able to download and view your demo. So it's the base default install of the platform that you're concerned with. This is why most of the best demos target Windows; DirectX is universally available, and the ability to use those libraries dramatically reduces the amount of code in the demo executable.
The same is true of OSX, but other Linux/UNIX variants are really problematic, because there's often no such thing as a standard install. And good luck as far as drivers for hardware-accelerated 3D go.
That said, it's really up to the individual group or competition that you plan to submit your demo to. You'd be best off contacting one of the members or organizers to see what their rules are. If you're just doing this for yourself, to post on the web, then you get to decide what seems fair. The more restrictions you place on yourself, the more impressive the demo ends up being.
If you're really serious about a 64k demo, though, you'll use assembly, not an interpreted language. You only benefit from something like Python if you can get short text to expand into a very complicated function in the stdlib. Most of the places where that matters for a demo are related to graphics and sound, and Python's stdlib doesn't provide much (nor should it) in either regard.