I want to make a game (something like theses) in C++ (Visual C++). Now a graphic game needs to refresh its picture quite often.
I can print around 20 blank lines. This method is unefficient and quite "laggy". What I need is something fast and efficient and that cause no memory problem because the game will process a lot of data (like mouvements, scores, coins...).
I've also tried to use system('cls'). This is quite bad because can "kinda" gives the player an epileptic attack!
Is there a better solution??
Thanks.
The command line has no image output. The only way you can fake it on the command line is the way you have described it.
The way to make a game efficient is to create a window yourself and then draw with DirectX or OpenGL something into that window. Then you can clear it and redraw it. This might not satisfy you at the moment, as it sounds more like a quick project. But in the long run, you will not be happy to "draw" on the command line if you search for efficiency.
Related
I am trying to make a simple QT android app, but basically my problem is that on my main screen I have about 250 little images that i want to scroll. But I really need the scrolling to be fluent and fast. First I tried it using QML but it wasnt really fast, then I tried to make the app in qt designer and use widgets but that was very slow. Then I tried using openGL but on android I can only use openGL ES and I cant find so much examples because every example that I find is much more advanced than I need.
But basically my main question is, what do you think is the best way to solve my problem and if its openGL which way of using it is the best that could solve it?
Thank you.
Neither approach should have problems when scrolling when compared to a native application on the same device. Check the following:
Make sure to measure performance only in release-builds, with QML debugging disabled and no debugger attached.
Maybe your device simply can't keep up with so many images in one view - then it's not a Qt problem. Compare with a 'native' java-App to see if this is the case.
Check if you implemented everything correctly; e.g. check if theres anything running in your main-loop or some events happenening repeatedly which consumes CPU time
And some more general advice:
Downscale your images to the appropriate view-size before giving them to the UI, as they might have to be re-scaled on every frame-update and/or consume graphics memory otherwise. E.g. dont set the source to a 1024x1024 image when it's going to show in a 64x64 view
Remove transparency from the images if they are going to display on solid-colored background anyway.
Dont overlay the images with other widgets/controls
If you're still getting a 'slow' UI, maybe try to merge all or multiple images and their surrounding UI/Controls into one or more bigger images
Very long views are not user-friendly. Maybe implement a pager or tab-view etc. to divide your list into multiple views. This way you can also decrease load-time
Dont try to implement an interface in openGL yourself. It's unlikely you'll make a better one than you already get with QtWidgets and QtQuick.
I'm a Rails/web developer with little experience with C++, so I'm not totally sure what direction to head in: I'm looking to build a simple simulator that I can use to test an algorithm I'm building that converts standard images to radial coordinates, and all I really need to be able to do is to plot points (which will represent LEDs) on a blank window and continuously refresh them (the LEDs blink). I don't want to build a gui; command line is fine, as I'll be the only person using the tool.
I'm not sure whether this is even possible or not... I did some Java programming years ago and I remember being able to pretty easily open a window and render images in it. Is there a C++ equivalent?
Thanks in advance!
What you are describing is a perfect fit for a GUI application, rather than command line, as far as I understand.
But if you want something really simple, and not spend some time learning a GUI development framework (MFC, Qt, WxWidgets, etc), you should check the following resources:
character based basic console graphics
some more advanced console graphics with blinking, box drawing, etc.
using full GDI graphics on console
It's not that easy in C++, because there is no standard way in doing this. It's not part of the language. There are a lot of frameworks though, some lightweight and some bloating. It also depends your platform. Anyhow, I think I would use OpenGL and do that calculation thing in a shader. That way you don't have to recompile and rerun all the C++ code. You can even do it in way that updates the GPU shader whenever you save your shader file giving you immediate results.
I need to implement a simple sound editor with a specific signal processing function.
I want to display the sound information vertically as a large picture - 1024 x [large height].
So I'm looking for Qt's best way to implement low-cpu-consuming vertical scrolling similar to web-browsers scrolling.
You need to create a custom widget by overriding it's paintEvent().
Have a look at this self-explanatory example on how to create a following widget.
A normal QScrollArea will give you what you want 99% of the time. But you're wanting to create a bitmap of potentially massive size, and you want to store it in RAM - you will quickly run out of space.
You are probably going to need a need a system where you save the image to file, and use the scroll area's bounds to intelligently load it's contents from the file (and a certain size around it to make it smooth) - Qt does not provide this. This is hardly groundbreaking stuff, so a web search for "scrolling very large images" or something similar should give a smart result.
If your intention is to plot STFT data, then you can easily adopt one of the widgets in the QWT library:
http://qwt.sourceforge.net/
Anyway, take a look at it, it is a great source of inspiration and the code is available...
I need some help - I'm trying to create a roguelike using C++, and at the moment, I have a very simple little screen going, with a void() that generates a map, using "#" for walls and "." for floors. It can draw the player by comparing some integers which map the X and Y values of the player.
I even have a little HUD which will display the player's stats.
But, the issue is, this is all being designed using a typical command-console window, and I'm starting to think I'm doing this wrong.
I want the player to move around this big empty room I have, by using the numpad -- this works. By using a Switch, I adjust the X and Y player value and then redraw the screen again.
Here's the issue. This actually redraws the screen all over again: it adds the 20-odd lines all over again, every single time I move. After a few moves, I have a command console window with text going for hundreds of lines.
So what am I doing wrong? Is there a command I don't know about to clear the screen?
Or am I doing this wrong from the start -- for instance, you have to press 'enter' to input your command, something that's not in any other roguelike. I'm a novice programmer, so any and all help is appreciated!
Thankyou!
Edit: Okay, thanks guys, I am now using PDCurses and trawling the docs to work out how to use the thing! Thanks again so much! Somebody please give the guy who suggested this a big tick! :D
What method are you using to draw the screen, just normal iostream? For this kind of work a library called curses is normally recommended. It would let you draw text anywhere on the screen without scrolling or redrawing the entire screen.
I don't know of any reliable way to do it with portability, maybe try looking for some console oriented lib... Anyway under Windows you can still use system("cls");
You can use the ansi escape sequence: printf ("\33[2]").
Could anyone suggest me a particular way to implement animation in my Dialog-based mfc program? The animation that I am intending to add is like a construction digger machine graphic that would read the values of the machine parameters and change the shape of the graphic accordingly. Most of the information is read from a text file in terms of the parameters, so I just need to be able to get the animation working.
Thanks for your help in advance.
Well, GDI is easy but ugly and quite slow, GDI+ is also easy, but nicer although generally slower. OpenGL or DirectX are much, much faster but quite hard to program. Other libraries, such as cairo, are also available.
I'd suggest to start with the easiest (maybe GDI+) and see if it is fast enough for you.
Do do that, just Invalidate() the control where you are drawing in a timer, (or when you receive new data), and paint the whole graphic in the OnPaint() function. A basic improvement is to Invalidate() only the region where the new data affects the picture.
If then you notice that your code is not fast enough, come back and ask how to improve it. A concrete example will make it easier to get a more useful answer.
there are lot of articles. Most of them based on drawing in device context
http://www.codeproject.com/KB/GDI/flickerfree.aspx
http://www.codeguru.com/cpp/g-m/bitmap/article.php/c4879
http://www.codersource.net/mfc/mfc-gdi-plus/animation-control-mfc.aspx