How to draw graphics on screen without using any framework or library? - c++

I want to manually draw the graphics, what that mean is without using any library or frame work like QT, directX , whindow.h .... like giving command to every pixels on the screen to show some specific color at different time. Every body gives tutorials on based on these library or whatever they are called. What i want is to make my own GUI. As far as I could think it is going to be very complicated, hard to learn and to understand, messy and a lot of time consuming, but I am ready for that. I need some resources to understand that.
and Yes i know C++ so it would better if I had to work with this language but I will learn other language if it is required, just i want to know which language i should learn.

In the old days, you could write directly to video memory with no help from the operating system/ROM. Today, on current hardware, you have to go through the operating system in order to write to the screen. That means using a separate library (like Qt) or using the OS features (windows.h). You could use directX or something and get more raw access to video memory, but that is still using a library/framework.

If you want with C++ and native Windows API (without DirectX) , you should use GDI(Microsoft Graphics device interface) + MFC(Microsoft Foundation Classes) this is a classic implementation of Windows GUI, If you want complicated graphics with shaders you need DirectX/OpenGL without hesitation. meanwhile if you want higher programming framework you can use C#(CSHARP) or Java.

Related

PNG Texture OpenGL es 2.0 Android NDK

I'm developing a game, actually my first game, so I'm new in this world, I'm using OpenGL with NDK and C++ for the render part, and I call it from java with JNI. I'm stuck with the textures topic, since I need to use PNG with alpha channel and use TTF for some text.
I can include the libpng, but since I'm using the experimental gradle puglin, I don't know how to add the library and use it, I saw that the library can be precompiled and be added, but from what I saw, only for one architecture, then, I don't know if I'm wrong, but I think if I add the source code of the library and compile it with the program, I think, it will be compiled for the architectures that I need (MIPS, 64-bit ARM, x86, 64-bit x86, ARM), so that is one, I was thinking in pre-convert the png in raw RGBA and use that vector directly with opengl but again, I dont know how to do this.
and with the TTF issue, well I am in blank, if you have any advice for this I would greatly appreciate it.
Thanks for your help.
You can build the whole FreeType engine into your code, or you can just use what's already part of Android: use Canvas to render glyphs to a Bitmap. You can find an example of this in Android Breakout. The game is written in Java rather than C++, but the Java-language GLES code is just a thin wrapper around the native stuff, so it's pretty similar.
There's a pretty good blog post about GLES text on Android here.
On a similar note, you already have a copy of libpng in your app. You can call through the Bitmap API to use it.
If you have as a goal the creation of an entirely self-contained native app, then the approach of calling into Canvas/Bitmap isn't viable. I don't think that's a particularly useful goal, however. You're better off separating the "game engine" from the game logic, e.g. have platform-specific "decode PNG" and "pass this pile of RGBA pixels into glTexImage2D()" functions, and platform-agnostic "use texture N".
Taking that one step further, your best approach is to use an existing graphics engine or game engine, and focus on creating the game rather than writing the engine. Learning about engines by writing one is a worthwhile endeavor, but if your actual goal is to write a game then you should focus on the game itself.

Library to that allows setting of individual pixels within a window

I am running Linux. I am looking for a library that will allow me to set up individual pixels within a window on screen. I am working on an embedded application and it would be a lot easier to develop my algorithms on the computer rather than the project. Im looking for something along the lines of display.setPixel(x, y). Does anybody know of any similar solutions? Im looking for something using C or C++
I suggest you start with SDL:
http://www.libsdl.org/
It also has some nice image loading routines, OpenGL and other stuff you may find useful. It can be used with either C or C++.

Mac dev - Help getting started with 2d games

I want to make some simple 2d games/clones (for Mac), but I have a few questions:
Should I use Quartz 2d or OpenGL (I don't plan to try 3d anytime soon)
There seems to be a lot of typedef'd things like CGFloat/GLfloat, which should I use?
Should I use Objective-C for the game too (classes) or just C? (I assume I'll use Objective-C and Cocoa for window and views.)
Is it fine to redraw the entire view each time? I don't really understand how the NSView's -drawRect dirtyRect parameter works, how does it know what I want to update?
Are there any good tutorials for this?
Thanks.
Quartz or Core Animation vs. OpenGL really depends what you're trying to do. If you want simple drawing and animation, use Quartz or CA. If you want fast/powerful games, use OpenGL. Eventually I'd suggest learning both.
For the typedef'd things, use whichever is meant for the specific system you're using. For Quartz/CA/CG, use CGFloat. For OpenGL, use GLfloat.
Objective-C vs. C also depends on the speed you want. Objective-C adds a little bit of overhead but will (obviously) let you create much more object-oriented games. I'd suggest using Objective-C if you use Quartz and Core Animation, and either Obj-C or C if using OpenGL. However, if you're doing this on a Mac (e.g. not for iPhone), you probably won't see much difference unless you're doing complex fast drawing.
I'm not entirely sure about drawRect, but this question has some information which may answer that question for you.
For an intro to Quartz, I'd recommend this tutorial, and I've always heard the NeHe tutorials recommended for OpenGL.
If you use SDL with either Cairo or OpenGL, you get virtually the same programming model, but you get cross platform compatibility virtually for free. You should even be able to continue using objective C for the bulk of the game, if you want.
How graphically intensive do you want to get? Cairo will probably be easier to just get going with for 2D.

What environment should I use for 3d programming on Linux?

One thing I always shy away from is 3d graphics programming, so I've decided to take on a project working with 3d graphics for a learning experience. I would like to do this project in Linux.
I want to write a simple 3d CAD type program. Something that will allow the user to manipulate objects in 3d space. What is the best environment for doing this type of development? I'm assuming C++ is the way to go, but what tools? Will I want to use Eclipse? What tools will I want?
OpenGL/SDL, and the IDE is kind-of irrelevant.
My personal IDE preference is gedit/VIM + Command windows. There are tons of IDE's, all of which will allow you to program with OpenGL/SDL and other utility libraries.
I am presuming you are programming in C, but the bindings exist for Python, Perl, PHP or whatever else, so no worries there.
Have a look online for open-source CAD packages, they may offer inspiration!
Another approach might be a C#/Mono implementations ... these apps are gaining ground ... and you might be able to make it a bit portable.
It depends on what exactly you want to learn.
At the heart of the 3d stuff is openGL, there is really no competitor for 3d apps, especially on non-windows platforms.
On top of this you might want a scenegraph (osg, openscengraph, coin) - this handles the list of objects you want to draw, their relationship to each other in space the ability to move one relative to the others, selecting objects etc. It calls opengGL to do the actual rendering.
Then on top of this you need a gui library. Qt, Fltk, wxWigets or one built into the scene library or written directly in openGL. This handles the menus, dialogs frames etc of your app. It provides an openGL canvas to draw into.
Personal choices are openscenegraph and Qt
For the 3D part, I strongly recommend the SDL Library with the OpenGL library
You can get some tutorials here
Qt has a pretty decent OpenGL-based graphics module.
Maybe you should consider using a graphics rendering engine such as OGRE. Coding a CAD program from scratch using OpenGL will take lots of time.
On Linux you have no competition to OpenGL.
It's one of the big players in the 3D field, so it's definitely worth learning.
This site has some excellent guides and code examples (on various languages).
You can use OpenGL with many languages, naturally on C and C++ but also for example with JAVA using LWJGL or other API's.
If you want to program at "a higher level" than opengl, use vtk. It is quite easy to get started and has bindings to many languages.
See www.vtk.org
you may use OpenSceneGraph for rendering.. it is an OpenGL based library..
and you may use OpenCascade.. it is good for 3D modelling...
we are implementing such an IDE at work and we use these things.. using pure OpenGL may be hard for you... anyway you may try...
for interface it is good to use Qt..
and i suggest you to use Eclipse if it is Linux..
(if it was Windows, suggestion would be Visual Studio)
For a C/C++ IDE, you have the following options:
KDevelop - KDE-based
Anjuta - GTK-based
Netbeans
Eclipse
Of course, you could also use a language like C# or Java:
Best OpenGL Wrappers for Mono and .Net
JOGL
There's really no reason why a simple CAD application would have to be written in C++.

Using an existing C++ engine on the iPhone

I come from a C/C++ background and more recently flash. Anyway I wrote a 2D engine in AS3 and would like to get it running on the iPhone. To start with I converted it to C++. As a test I wrote a very simple C++ engine and added the files to a standard view-based application in XCode. I then added a UIImageView that covered the whole iPhone screen.
The way my test engine is set up at the moment is that each frame it renders the result to an image which is then used to update the UIImageView every frame. Assuming I can pass input from the iPhone to the C++ engine this seems like a fairly platform-independent solution. Since I have been coding for iPhone/Mac for less than 1 day I was wondering whether this is the standard approach to getting an existing C++ engine running on the iPhone and if not, what is?
There's no problem in you rendering into an image and refreshing that image, but you get no acceleration from the GPU using this technique. So you'd be burning a lot of CPU cycles, which in turns eats battery.
If the objects you are rendering can be described in normal graphics primitives, be sure to use the drawing APIs which are optimised for the platform and can delegate work to the GPU.
An alternative approach is to make use of OpenGLES, but this has a learning curve
Yes, that is a fairly normal way to handle it. Generally you would either use small Objective C stubs for your events and things like pushing out the frame, or you would setup an OpenGL context and then pass it to your C++ code.