C++ pixel level control over graphics - c++

I have been looking all over the web for the simplest solution for this, and currently I have come across nothing that seems simple enough for my needs.
I am looking for a way to manipulate a matrix of pixels manually in C++, platform independent.
Does anyone know of a library that is simple to use that will help me obtain this?

Use SDL

Use OpenCV

By virtue of it being platform independent, you're probably not going to find a library that does only this. There are libraries like SDL and directFB that will let you do this, but not without extra baggage. X11 may even be a better choice. It supports things you don't need, but it also allows you to easily render pixels directly to the screen (or window, as the case may be).

Related

Drawing a pixel in C++

I've been looking everywhere but cannot find an answer, is it possible to draw a pixel in C++ without a library, to the console, where I decide where to plot it(x,y).If not, how does a library manage to do this, I read it had something to do with the library gaining access to the drivers on the computer, but even then its still part of the C++ program.By the way I have never had formal programming education so this may seem silly.
This is possible, but highly dependendt on your operation system. You will have to use the OS API, because the C++ standard in itself doesn't have any idea of that kinda stuff.
For example, Windows has the SetPixel function that can be used on the console window. You can get the console window by using GetConsoleWindow and its context using GetDC.
That said, it's one of the less orthodox things to do, not portable and hard to predict - redraws of the console window will erase your content. Reconsider your options, and think about whether using a library might not be the better idea.

How to draw one pixel

My question is that, how Can I draw one single pixel on the screen using C++ native libraries and functions? I mean not to use external functions or libraries. How is it possible?
Something Like this:
int rgb = {255,150,113};
nativeLibrary.drawPixel(0,1, rgb);
A fancy example just it is.
You can't. C++ does not (yet) have any native graphics or GUI libraries.
C++ may eventually add graphics into the standard (they were considering it), but for right now, the C++ standard does not include graphics.
You can take advantage of other standards in order to write a pixel to the screen, though. If you're on Linux, there is already an answer up.
If you're using VGA, you can actually write directly to the VGA buffer (WARNING: WAY OUTDATED Like "meant for DOS" outdated). You would probably use C++'s inline assembly to set the render mode instead of whatever that page uses, then use a regular unsigned char* instead of a "far" pointer to access it. Although you probably aren't using VGA and probably don't want to use assembly (especially inline assembly).
So what do you do outside of that? Nothing, really. You need to use an external library specifically to render, so probably OpenGL or DirectX or some library making use of either.
Like the previous answer, there no native library to deal with images. However, if you are working in Windows API and particularly MFC, you may use CBitmap class.

C++: Multiple Sounds without Additional Headers or Libraries

This is my first post here. I am trying to write a program that plays background music, while still allowing for playing sound effects (i.e. music with gunshots). I wish to play multiple sounds at once WITHOUT using any other libraries or header files. I don't want to use anything besides what comes with Windows XP and my compiler. I don't want links to other libraries, I need example code showing how to do this using vanilla Windows. I am using Windows.h. I have done research into this, and have yet to find an answer that meets my needs. I have heard that multiple threads might be an answer, but cannot get them to work. I am relatively new to coding.
Thanks in advance!
I know you've said you want to keep it simple, but it sounds like you want to use DirectSound. It provides one primary buffer (good for your background music) and a series of secondary buffers (good for your sound effects). Its very easy to work with, and doesn't require much more than linking dsound.lib
Also, completely unhelpful: You should be sure to upgrade to Windows 7 or 8 before April. Microsoft will no longer support it and you'll be a great risk for exploitation.

Best general cross-platform solution for drawing (primitives, lines, etc) in C++?

I've had much experience writing in Java, python, C#, and C, mostly for hobby. In all of the applications I've coded that involve displays (simulations, graphers, etc.), I've always just used the stock "Canvas" class of whatever framework I'm using (Swing Canvas, .NET Canvas, pygame once for python).
The downside of this is that all of these have slightly different paradigms in drawing.
I'm starting a project in C++ and was wondering what the best solution is for cross-platform drawing. OpenGL is obviously very low level, but some sort of library on top of OpenGL would be good. I've heard of/read about things like Cairo, SDL, etc., but don't yet know what to go with. I'm already using wxWidgets for interface, but would prefer to use something more standard instead of just a wxWidgets canvas. Obviously, the ability to draw lines and shapes is important, not just display pictures or whatnot.
Thanks for any direction!
I would consider using Qt, and notably its Graphics View framework. (Qt works on Linux, Windows, MacOSX).
SDL is SimpleMedia Direct Layer, which is basically a common interface to interface with the framebuffer and audio devices. If you wanted to create windows and such, it doesn't have general purpose constructs that work cross-platform.
Cairo is for drawing graphics, but still operates at a level that's lower than what WxWidgets provides.
C++ doesn't provide anything standard, so either you go with some platform specific, or you use a cross platform library like Qt (already mentioned by Basile) or stick with wxWidgets. Both are popular and widely used, though Qt is probably much more well-known and used (though that is just opinion). I've used Qt for work and it is very much cross platform and pretty easy to use (but very extensive, so prepare to read a lot of documentation). Luckily it also has a lot of documentation and many examples available.
Plus, both wxWidgets and Qt have bindings in many languages, so you could take the knowledge with either and use it with many other languages.
Open Frameworks is very easy to use and comes with a lot of examples...
it's platform independent and somehow reminds me of processing

Starting with OpenGL and C++, proper path?

I need some specific and some general advice. I'm a fairly proficient Java programmer and a very experienced web programmer, but I would like to get into software development and I've been tackling C++. I have a great idea for a game I'd like to do, and I realize it will be a huge undertaking--but I'm looking at it more for an opportunity to learn C++, wrapping, really whatever I run into in the dev process...
But I can't get my foot in the door conceptually! I can handle the C++ aspect fine, it's just setting up the graphics, the RIGHT way, that's confusing me. I've run through a bunch of tutorials for OpenGL with C++ that all say the different things, none of which I can really get to work...
Some say to use GLUT and GLEW. Some say GLUT is dead and that FreeGLUT is the thing now. Some ignore those entirely and use a bunch of files like "glaux.h" that I can't seem to find--and other tutorials devoted to AVOIDING "glaux.h"... Most tutorials I've found come with the caveat in the comments that their version of OpenGL is dated and I should be using newer libraries-- and still others with 3rd party libraries like Ogre and Aurora.
I've been looking through a bunch of books and tutorials that ALL have an almost completely different setup for using OpenGL with C++. I realized there is probably not one right way of doing it, per se, but I'm looking for the way that is the most current, most popular, and will maximize the usefulness of the project as far as my learning... Any links to tutorials or advice in general is much appreciated.
BTW, I'm using Visual Studio Express 2010 (good idea?). My game won't be too graphically intense (isometric 2d) but will require a TON of logic and a TON of data, which is why I want to speed things up by using C++. Any other insights on better ways of doing it than using c++ for login AND graphics (from an industry perspective) are also very valuable to me! Thanks in advance!
Assuming you're learning OpenGL as a learning experience, I would recommend you this:
Use GLEW, no argument. Just do it, everyone does
Code only to the core profile. By default, OpenGL accepts old command (eg fixed function pipeline) that will later disappear, and you don't want to waste your time on that. Specifically: learn about VBO's, texture's, and, most of all, learn about shaders.
Forget about glaux and glut. Freeglut is a good and very standard option. A less obvious choice would be qt, but it's QGLWidget allows you to easily make gl calls, and not worry about context creation and all that. And it's dead easy to add gui options, which is always very nice to have when programming graphics.
To actually learn OpenGL, I would recommend http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html. Nehe has that problem where more than half of the stuff is useless to learn, and there's a lot of fluff (window creation et al) around it.
But, I wouldn't really recommend OpenGL as a way to learn real-time graphics programming. Your alternatives are not limited to DirectX. I learned a ton of graphics coding from working with Ogre3D. You still have all the concepts at your disposal that you need to know (working low level with Vertex and Index buffers, Textures, shaders), and implements tons of stuff to make your life easier. You might not learn the ins and outs of a specific API, but you will learn all you need to know conceptually. When I became a graphics programmer, I hadn't written a line of DirectX code, but I got to grips with our engine really swiftly. I learned the actually calls very easy after that. Know the hardware, and the concepts. The actual implementation changes over time anyway.
Oh, and just in case I haven't repeated it enough. LEARN SHADERS
The best tutorial around is (arguably, as anything "best") Nehe opengl tutorial. At least, this tutorial has been suggested for many years.
Also since you come from a Java background you might prefer C# bindings for opengl from frameworks such as Tao, but the actual setup might be harder than say, downloading samples and running them.
It's easy to see where the variety of choices available for OpenGL with C++ would be a bit bewildering. For the most part, Java gives two a pretty clear-cut choice between two possibilities (do you want a scene graph or not?)
The situation with C++ is certainly more complex.
Glut: This is basically an OpenGL-oriented application framework. It was apparently written primarily to allow examples to be short, but still work. The original implementation has some pretty well-known bugs, and hasn't been updated in over a decade. I would only use it in roughly the originally-intended context: short samples/examples/demos.
glaux: The story here is sort of similar to GLUT. It has some memory leaks that have been known but unfixed for over a decade now. It was never portable in any case. I'd avoid this one completely.
GLEW/GLEE: These allow relatively easy use of the functions added in newer versions of OpenGL from OpenGL implementations (e.g., Microsoft's) that haven't been updated to include headers/libraries to provide access to them directly. I prefer Glee by a small margin because it initializes itself automatically, but both work fine.
FreeGLUT: This has been updated more recently, and some of the bugs expunged. It still hasn't done much to improve the basic design of GLUT though. Probably a better choice for short demos/samples, but still not (IMO) suitable for much serious use.
Ogre3D: This is much bigger than any of the preceding libraries. It's a full-blown scene graph library, with texture loading, defined file format, etc. A solid library, but be aware that if you use it, you won't normally use OpenGL directly at all (e.g., on Windows, it can render via either OpenGL or Direct3D without changing the source code at all).
OpengSceneGraph: More often used for scientifically-oriented applications, but most closely comparable to Ogre3D.
FLTK: a small, lightweight GUI library that runs on top of OpenGL.
GLFW: In the same general spirit as GLUT, but it's been updated much more recently, doesn't have nearly as many bugs, and is (IMO) a nicer design -- minimal but still suitable for "real" use.
You should be using OpenGL if you want to write portable 3D applications. Windows, Linux and Mac OS X supports it.
You might want to take a look at NeHe tutorials. It's one of the best OpenGL tutorials available on the web.
My understanding is that if you want simple support for a recent version of OpenGL you'll have to leave Windows-land, so try take it in stride when getting started is ... complicated.
I think OpenGL is probably the right choice. You might also want to consider DirectX (which is better supported on Windows), but I'm personally not a big fan of it. You could also learn C# and use XNA, but if you want to learn C++ it just defeats the purpose. (I also can't help mentioning there's a good chance you could make it fast enough without C++)
I have to agree with the others that NeHe's tutorials are pretty much classic. You might also want to consider the OpenGL Red Book, but that costs money.
Regarding the 3rd paragraph, GLUT is old (and for that matter so is GLU), but if you see a good tutorial that uses them, I don't see anything wrong with them. Once you have your feet wet you might want to consider ditching GLUT and using SDL which I believe is a lot more 'alive'.
As far as GLEW goes, I've used it with success and it's nice if you want to do something fancy like shaders on Windows. However, I would say don't worry about it at first, because it will increase your setup time and keep you from getting to the fun stuff :)