How do I regulate the SDL sprite speed in C++, I know it's something to do with the framerate, but I'm not 100% sure. I know how to do it in PyGame, but SDL & C++ are slightly different.
Recommend following the lazyfoo tutorial on this.
Related
I have a relatively simple application which currently utilizes OpenCV to grab an image from a camera using cv::VideoCapture and view the resulting image in a window using imshow() running on OS X El Capitan.
In between I'm doing some basic image modification but this is not crucial to my problem.
Since the GUI implemented by OpenCV is pretty basic I decided to redo it using wxWidgets. I got it basically running similarly to the implementation linked in the tutorial section of wxWidgets. (Updated it to C++11 etc. but the idea is pretty much identical. Code is located on github.)
Now heres my problem: In best cases I get half the framerate as I get with the OpenCV only solution. OpenCV uses qt underneath. But when I look into the stack trace it comes down to similar function calls using CoreGraphics.
So my question boils down to: What is the best way do draw an image to a window with a framerate > 20fps using wxWidgets on OS X? Currently I use the DrawBitmap() function.
Bonus question: when I have the window on my Macbooks internal Retina screen the framerate gets even worse. Is there maybe any preprocessing/scaling on the picture I should do to take off load from the GUI-process?
The fastest is probably to use OpenGL (although I'm less sure about this under OS X which is not very OpenGL-friendly AFAIK), but I'm not really sure if the bottleneck is really DrawBitmap(), it could be the code doing the conversion to wxBitmap in the first place: if you don't use raw bitmap access, it could be quite slow.
So I have a bunch of experience with C++ and Win32 programming and I am looking to create a 2D game with a couple of friends of mine. I have also dipped my toe into DirectX and OpenGL, but would prefer to use as simple of a library / API as possible when developing this game both for reducing the learning curve and making the development process easier / faster. However, I don't want to limit myself to much with regards to what I can and can't do in my game based on my choice here. What functionality / features would I lose out on by going with something like Allegro or SDL vs jumping straight into OpenGL lets say. I realize you can do other things aside from just graphics with Allegro, etc., but will I be able to build a fully featured game with something like Allegro?
Yes, it is possible to create a good game with libraries like Allegro. There is a few nice games in their depot to prove that. And I remember a few shareware games created using Allegro. It all depends on what kind of game you want to create.
But AFAIK Allegro and SDL are C libraries and if you are familiar with C++, you may try SFML or Cinder which could further simplify the process.
If you are only into creating a game comfortably and don't care about the technology used maybe using a complete engine like Unity3D or Unreal engine, which are free until you make a considerable profit out of the game.
You will miss out the lighting part you generally do in a fragment shader. Other than that, using a pure 2D api can significantly reduce your amount of code, because you do not need to write your own shaders, nor the interface between shader and c++ code which is often even more work and maintenance than the shader itself. Since shader code is mandatory in modern OpenGl my recommendation is SDL2.
I need to smoothly zoom in/out and pan an image (for a slideshow) with the sdl library.
I've tried rotozoom from the SDL GFX library but it's far away from smooth.
What would be the best approach here?
If "vanilla" SDL seems too slow for you I'd suggest switching your drawing code to OpenGL. That way you'll get hardwareaccelleration and your issues should go away:)
Using OpenGL coupled with SDL is very easy and there are lots of tutorials on how to do it.
I've played around with GLUT, but I've also read about SDL and one or two other graphics libraries. All I want to do at this point is 2D work. For what I'm doing right now, pixel by pixel plotting is all I need (say, plot(x,y,color) or something of the sort), but in the future I would appreciate the use of sprites. I've given point plotting a go with GLUT but it's rather non-intuitive coming from a B.A.S.I.C. background.
I work on both Ubuntu and Windows, so solutions for both systems are welcome.
SDL is probably a good choice; another option to look at would be Qt (just subclass a QWidget and override its paintEvent() method and do your pixel plotting inside that). Qt can also provide windowing/infrastructure support for OpenGL graphics if that's your preference.
I would like to program some graphic figures such as line, circle,etc. I have used turboc++ 3.0 for
dos graphics. I would like to do the same with the compilers dev c++ or code blocks or vc++.
I would like to implement dda and bresenhems line and circle drawing algorithm.
how should I go about implementing these programs through these compilers (not the command line tools).
I have a really vague picture of graphics programming.please help..
please note : I have a nvidia graphics card 1gb.. so I cannot use dos graphics (I think the card is the reason).
If you're wanting to play around with graphics code to draw objects and do things with them may I suggest that you skip the whole Windows/GDI/DirectX/ thing completely and take a look at Processing?
It's basically Java, so you won't have to jump too far for the language, but more specifically it's designed for playing around and experimenting with graphics, so may suit you perfectly.
You really have a vast variety of options. Starting from GDI (not hardware accelerated), finishing with a heavy stuff like DirectX, OpenGl. There is also a nice library, called SDL. It does not really matter what technology you will use to solve your problems. If the speed is not a matter, i think GDI is the right and most simple choice.
You may want to start off with these tutorials:
http://www.tutorialized.com/tutorials/C-and-Cpp/Graphics/1
From the sound of things, you're trying to produce a program that runs on Windows. In that case, you don't need to implement basics like Bresenham's algorithm to be able to draw lines and circles. Windows provides MoveTo and LineTo to do basic line drawing, and Ellipse to draw ellipses -- and if the axes are equal, the ellipse it draws will be a circle.
Edit: It also sounds like you haven't written any code for Windows. This is quite different from writing code for DOS, so you'll probably need a good book. Charles Petzold's Programming Windows is a classic (though for C++ you'll want a somewhat older version -- I believe the current ones concentrate on the .NET languages).
I am using the powerful cross platform project: http://cimg.sourceforge.net/ .
you have there all primitives and more.
I you wish to use your GPU power you can use glut library for OpenGL.
cheers Arman.