LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Eclipse, OpenGL, MinGW? (https://www.linuxquestions.org/questions/programming-9/eclipse-opengl-mingw-4175535359/)

Birdman48 02-28-2015 06:53 AM

Eclipse, OpenGL, MinGW?
 
Hello. I am intersted in writing C++ progams that can display simple lines or shapes that will represent some objects. For example, a grid that looks much like a crossword puzzle and an oject that occupies one of the squares, and this object will navigate from one end of the blank squares to another.
Anyway, I figure I need some graphics capability but graphics.c is out as I'm on a linux machine.
I've been reading about openGL, MinGW for Eclipse and I have big trouble installing all this stuff correctly. I have installed Eclipse Luna and use it for Java and have the C++ CDT as well. But I don't have graphics capability. I want to draw simple two dimentional shapes.
Can you tell me what I need to install, where to install or direct me to the correct instructions please?
I have OpenSuse 13.1

TobiSGD 02-28-2015 08:03 AM

For your specific use-case you probably go best with forgetting about OpenGL and just use a cross-platform toolkit, like Qt, it will give you all the capabilities you need.

ntubski 02-28-2015 09:52 AM

Quote:

Originally Posted by Birdman48 (Post 5324653)
I'm on a linux machine. ... I've been reading about openGL, MinGW for Eclipse...

MinGW creates Windows exes.

Quote:

I have installed Eclipse Luna and use it for Java and have the C++ CDT as well. But I don't have graphics capability. I want to draw simple two dimentional shapes.
Do you specifically want graphics in C++? Because you could do this in Java: http://docs.oracle.com/javase/7/docs...raphics2D.html

Quote:

For example, a grid that looks much like a crossword puzzle and an oject that occupies one of the squares, and this object will navigate from one end of the blank squares to another.
This sounds like some sort of game perhaps? SDL is popular library for this sort of thing. It also has some functions for setting up OpenGL surfaces, but you'll only need that for hardware accelerated 3D stuff.

Compared to Qt it's a lot smaller and simpler because it doesn't include UI widgets (buttons, text boxes, etc).

Ace Blackwell 02-28-2015 10:11 AM

I'm a novice so I wouldn't take my advice as gospel but I am using Eclipse and Allegro 4. It's good for simple console programming and using graphics. (Similar to MS Graphics.lib) However learning from ground zero, I would suggest using Allegro 5. As I understand it, it's event driven.

Plus Allegro libraries can be used on both Linux and Windows. (I'm running a duel boot). Only thing to remember, if you want to run your game on machines without the Allegro library, you will need to compile your game with Allegro static library. In short, it makes your program bigger by including all the info needed to run your game independently.

Again, I'm not an expert, but this should be enough info to Google the gaps. And send your game once you have it. :)

Good Luck
Ace

manu-tm 03-01-2015 11:47 AM

If you want graphics capabilities in your C/C++ program, you need to use a graphics library.

But OpenGL is for 3D stuff, and GTK or Qt are for GUIs.

So, for 2D graphics: SDL, Cairo, ... (others that I can't remember at the moment.) Googling 'LibSDL' and 'Cairo graphics' should give you relevant links. Once your choice is made, all you will have to do is install the development packages and read API docs.

TobiSGD 03-01-2015 11:51 AM

Quote:

Originally Posted by manu-tm (Post 5325192)
But OpenGL is for 3D stuff, and GTK or Qt are for GUIs.

Qt is not a GUI framework, but an application framework. It is totally possible to write Qt applications for the console, it also has widgets that allow 2D drawing and access to OpenGL.
But you are right, a specialized cross-platform library may be better here, depending on how complex the application is.

Birdman48 03-01-2015 12:04 PM

This is just a learning tool for myself. I like to see results in graphical form.
The Cairo tutorial is very well written but the program code looks like a huge learning curve for me. Oh well, it's Sunday and it's sleeting outside - might as well.

Trying to download, message says it's already installed. Now I wish I could just copy and psste a very simple program to see if it works.

manu-tm 03-01-2015 12:37 PM

Quote:

Originally Posted by TobiSGD (Post 5325193)
Qt is not a GUI framework, but an application framework. It is totally possible to write Qt applications for the console, it also has widgets that allow 2D drawing and access to OpenGL.

I've used GTK a lot but I don't know much Qt, so my mistake. Actually, you can also do 2D drawing with GTK, mainly with cairo functions.

Quote:

Originally Posted by Birdman48 (Post 5325201)
The Cairo tutorial is very well written but the program code looks like a huge learning curve for me.

SDL is more low-level and simpler.

Birdman48 03-01-2015 01:35 PM

Here's what I get when trying to use GTK in a C program.
Code:

jay@bird:~/CPP> gcc `pkg-config --cflags gtk+-3.0` -o window-default window-default.c `pkg-config --libs gtk+-3.0`
Package gtk+-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-3.0' found

I don't know where `gtk+-3.0.pc' is nor how to add the directory to PKG_CONFIG_PATH.

manu-tm 03-01-2015 01:40 PM

Have you installed the gtk3 dev packages?
Code:

sudo apt-get install libgtk-3-dev
EDIT: Ooops, sorry, this doesn't apply to OpenSuse. But you still need to check you have installed the dev packages. I don't know how you do that with zipper or yast.

Birdman48 03-01-2015 03:09 PM

yes I have those.

manu-tm 03-01-2015 03:30 PM

What's the output of
Code:

pkg-config --cflags --libs gtk+-3.0
?

Birdman48 03-01-2015 05:55 PM

Quote:

jay@bird:~/CPP> pkg-config --cflags --libs gtk+-3.0
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/pkg/wayland -I/usr/include/pkg/libxkbcommon -I/usr/include/pkg/wayland -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
Yeah they weren't installed after all - I just installed them, but I still get compilation error trying to compile:

Quote:

jay@bird:~/CPP> gcc -o window-default window-default.c
window-default.c:1:21: fatal error: gtk/gtk.h: No such file or directory
#include <gtk/gtk.h>
^
compilation terminated.

Birdman48 03-01-2015 05:57 PM

Here's the program I'm trying to run:
Quote:

#include <gtk/gtk.h>

int
main (int argc,char *argv[])
{
GtkWidget *window;

gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

gtk_widget_show (window);

gtk_main ();

return 0;
}

manu-tm 03-01-2015 06:14 PM

Code:

jay@bird:~/CPP> gcc -o window-default window-default.c
window-default.c:1:21: fatal error: gtk/gtk.h: No such file or directory
#include <gtk/gtk.h>
^
compilation terminated.

Code:

gcc -o window-default window-default.c `pkg-config --cflags --libs gtk+-3.0`


All times are GMT -5. The time now is 03:52 AM.