How to code in C++ using OpenGL in Linux

Hi,

I am newbie to this, i am very much interested to learn coding in C++ using OpenGL. Please give me some suggestion whether it will good or any other way for coding easily. what is the difference in using C and C++.

Give me some basic reference to learn about coding in C++ using OpenGL.

I am thankful for your reply …

Start here:

http://www.opengl.org/documentation/books/

In particular, the “OpenGL Programming Guide”. That’s a great place to start if you are new to real-time 3D graphics.

Also look at any GLUT-based OpenGL tutorials on the net:

http://www.opengl.org/code/

Im starting out as well… what version of openGL are you gunna use?

I use bjam from boost for building my projects. Otherwise, programming with GL is much the same as any C++ programming on linux. If you can compile/link your hello world program, you can also compile and link your GL application.

A good IDE on linux is VIM, but you’ll need to customize it for it to be useful (try the project.vim script for a start).

The best distro for development is gentoo.

This page was very helpful for me during my first steps in OpenGL world:)
I studied every tutorial, but instead of GLUT I used SDL for windows, keywvents, etc and DevIL for textures.

In your distro package manager, search for libsdl, libdevil. You need both: libary and dev package.

Kate (KDE) and Gedit (Gnome) are also excellent to write code.

If we are talking about IDEs VIM, KDE, Gnome are rather editors. I would suggest KDevelop on KDE or Eclipse CDT (I like the later as you can use the same IDE on Linux, Windows and MacOSX).

Code::Blocks is also pretty good, and is available for other platforms as well if you ever want to port something.

Woah - back way up there cowboy! A text editor is NOT a good recommendation for someone who’s just starting out, irrespective of however much you may like it for yourself. In particular if “you’ll need to customize it for it to be useful (try the project.vim script for a start)” - RED flag. The objective when starting out is to learn the basics of getting something on screen, and anything that distracts from that is a bad idea.

Likewise recommending a distro is not a good thing to do. This is about helping and giving useful practical advice to a new person, not about winning them over to your side of a religious divide. Let the OP choose whichever distro they feel most comfortable with themselves (they may already have a preference), pick a toolchain that does the heavy lifting for them, and focus on the important part - writing code that works.

I suggest you study the NeHe tutorials (search the internet). This is mostly to expose you to “what needs to be done”.

I also suggest you buy the latest version of the OpenGL SuperBible… which is “hands down” the best book for learning OpenGL (on Linux or Windoze).

I found CodeBlocks to be a good software development IDE on Linux. I tried Eclipse first, but it was an unbelievably painful experience (super-slow, obscure, always “difficult”).

I suggest you NOT start with an “old style” OpenGL program and “work up from there”. Start with VAO/VBO/IBO and a simple shader. This will cause some extra effort at the start, but you’re avoid polluting your “mind set” with worthless, inefficient, ancient nonsense that you then need to TRY TO “unlearn”.

I suggest you “ask around” on this forum and gamedev for anyone who has the “absolute simplest working OpenGL program for Linux”… then study it. This will likely be the very earliest version of some “engine” or “application” that later grew to monster proportions. All you want is the core when it could only:

  • create a window (xlib)
  • show the window (xlib)
  • create and “make current” a GLX/OpenGL context (xlib/GLX)
  • create efficient, natural aligned vertex structure (your code)
  • write a vertex shader and pixel shader (you do, in text)
  • make the shaders active (OpenGL)
  • create, initialize, activate an IBO/VBO/VAO set (OpenGL)
  • define uniform variables, set their values (OpenGL)
  • transfer vertex data to VBO (OpenGL)
  • glDrawElements() - (OpenGL)

I’m probably forgetting a few steps, but you’ll notice them when you read through references that describe minimalist OpenGL programs.

Most folks will suggest you adopt SDL or GLUT or some other system to simplify dealing with windows, context, etc. Personally I much prefer straight xlib/GLX/OpenGL without anything else “between me and the result”. But which approach you choose should suit your own inclinations.

Oh, but GLEW is probably worth the effort (to automatically declare all newer-than-ancient GLX and OpenGL functions)… but beware the first window chicken and egg “gotcha”. Hint: During initialization you need to create a window and GLX context and make it current with ancient GLX functions, THEN call glewInit() to make all “recent” GLX/OpenGL functions available, THEN delete the context/window/etc. THEN when you create any number of windows “for real” (for your application), you can write good code with the latest and greatest GLX/OpenGL functions.

I hope our combined wisdom (and suffering) helps you begin.

Religious divide? I’ve had many problems when I used distros other than gentoo. In particular the boost and other libraries tended to be less frequently updated. Many were missing and I’ve had to compile&update them myself. Once you’ve tasted the power of VIM, other editors don’t seem so attractive. So you invest some time in learning how to use it. There are a lot of resources, even a book or 2. So you learn once and profit from using an IDE, that you can use practically with every OS. The other editors are not as convenient to use outside of the linux/BSD OSes.

You don’t have to be a genius to learn how to use VIM, as some people seem to think.

All right ugluk, I feel like you’re trying to sell me a used car here :wink:

I do respect that gentoo/vi works well for you. However, we should all agree that the tools each developer prefers vary based on their tastes and experience. Those hailing from the UNIX world will usually be fine with a more minimal editing solution such as, vi or emacs, mixed with generous use of the shell prompt. However, those hailing from more pointsy-clicksy worlds such as Mac and MSWin will want an IDE (such as KDevelop or Eclipse) which “protects” them from the shell and from having to key in commands. There’s no “best” here. It’s what we each prefer.

Also, I think newbie’s are much going to prefer a distro that has a lot of “prebuilt” packages users can select from a GUI and automagically just download and slap on their system quickly with minimal effort (such as OpenSuSE, Redhat, etc.). The Gentoo philosophy of building everything isn’t really the best thing for a newbie IMO.

OK, whatever. The core point remains that VIM, for all it’s power, is not an IDE. It’s a text editor, and calling it an IDE is passing on misleading information.

It might be a damn good text editor (although from what I read it retains the modality of vi, so it’s not exactly newbie-friendly in that regard), but a true IDE has lots more to ease the workload and handle the heavy lifting. Features like integrated search and replace (across the entire project tree, not just the current file), integrated build, integrated debugging, integrated project management, integrated source control, etc; the “I” in IDE stands for “integrated”.

It may be possible to accomplish many, or even all, of these things by breaking out to the command-line, or by executing scripts within VIM itself, but it’s still not an IDE and it still won’t give you the convenience of a true full IDE.

Even many experienced programmers prefer using a full IDE for these exact reasons; you get to concentrate on writing code and your chosen tools handle the burden of everything else.

What you say is true to some extent, but VIM is extensible, people wrote games for it, there’s a debugger. Is it a wonder that there is an IDE for it too (project.vim)? But all these scripts, along with VIM are very light-weight, you won’t need a 100MB download to install them, unlike say eclipse, anjuta or some other IDE. You can build from inside VIM (:make command); it will scan the compiler output and jump to the point of error. It is enough for me, I don’t really need anything more fanciful.

As it was mentioned before, it’s just a matter of taste. Please let’s not start a Holy War here about it. VIM is something like UltraEdit or other editors! that allow you to add key triggered commands to it that execute scripts or whatever stuff. IDE is a different story, as there you have everything built-in.

But all these scripts, along with VIM are very light-weight, you won’t need a 100MB download to install them, unlike say eclipse, anjuta or some other IDE.

You say that in a way like nowadays downloading 100MB would be such a great burden. Actually it isn’t. Besides that, you still need a compiler, linker, debugger and a lot of other tools that you have to download in order to be able to compile/run/debug anything with VIM and that will end up in a similar sized download. Just you have to do it one by one.

Oh drop the whole “vim isn’t an IDE” thing already. I use :make, i use cscope/ctags, vimgdb, :argdo (for performing regular expressions across all source files), the only thing i add custom key sequences for is perforce integration. That’s it. Just because you don’t know how to use vim as an IDE, doesn’t mean other people don’t use it that way.

That being said, I wouldn’t recommend it to a newbie. It’s really powerful, but it has a steep learning curve. So does gentoo :-P.

For a newbie, I’d probably recommend Ubuntu and Eclipse with CDT.

So far, it seems like Dark Photon had the most level-headed post.

Not used it but some people really like CodeBlocks :
http://www.codeblocks.org/

Oh drop the whole “vim isn’t an IDE” thing already. I use :make, i use cscope/ctags, vimgdb, :argdo (for performing regular expressions across all source files), the only thing i add custom key sequences for is perforce integration. That’s it. Just because you don’t know how to use vim as an IDE, doesn’t mean other people don’t use it that way.

I never said it cannot accomplish the same tasks as an IDE, I just say it cannot be called an IDE, because it does not have all these things integrated into it out of the box.

However, I would be interested whether VIM has any functionality like Intellisense or any context sensitive autocomplete.

The only thing I mentioned that isn’t there out of the box from vim.org is gdb integration. You can grab that version of vim from the clewn project (http://clewn.sourceforge.net/).

“Intellisense” is called Omnicompletion in vim:

http://vim.wikia.com/wiki/Omni_completion

vim has it all, but is lightweight.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.