non-MorphOS OpenGL how-to
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    by the way all the nehe tutorials works on morphos too(excepte the shader one), just replace the windows code with the glut equivalent :D

    the nehe site is a must for anyone who approach opengl ( iremember reading it in 2002) :D

    also some tinygl examples are from the nehe site :P



    [ Edited by raistlin77it 19.12.2012 - 23:40 ]
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »19.12.12 - 22:35
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    Crumb
    Posts: 730 from 2003/2/24
    From: aGaS & CUAZ Al...
    I started with NeHe's tutorials but later I heard these were perfect examples about what you should not do :-)
  • »20.12.12 - 09:42
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 186 from 2003/10/23
    yes, because the tutorials are very old, now with the opengl 4.0 most examples are outdated
    I'm nerdy in the extreme
    And whiter than sour cream

    White&Nerdy 2006 Al Yankovic
  • »20.12.12 - 13:43
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    Jupp3
    Posts: 1193 from 2003/2/24
    From: Helsinki, Finland
    @raistlin77it
    Quote:

    by the way all the nehe tutorials works on morphos too(excepte the shader one), just replace the windows code with the glut equivalent :D

    Actually there's usually no need to replace, as there are links to "ports" to various other API's (glut, SDL) at the bottom of most tutorials.

    Quote:

    the nehe site is a must for anyone who approach opengl ( iremember reading it in 2002) :D

    I agree, it's important to know NeHe if you're learning OpenGL. It's important to know to avoid it. Always.

    @crumb
    Quote:

    I started with NeHe's tutorials but later I heard these were perfect examples about what you should not do

    I fully agree. Of course it's very farm from OpenGL 4.0 or even 2.0 (which already had shaders), which is pretty far from TinyGL aswell. But the thing is, the functionality used to draw in 90% of these tutorials hasn't been relevant since very first OpenGL versions, and even TinyGL can do better than that.

    In "non-OpenGL terms", NeHe is using:
    for(y=0; y<h; ++y)
    {
    for(x=0; x<w; ++w)
    {
    PlotXY(x, y);
    }
    }

    Instead of:
    BlitBitmap(picture);

    You are free to guess which one is both faster and more preferable.

    Not only that, it often also uses immediate mode in needlessly slow way (like drawing GL_QUADS from array, each within their own glBegin() ... glEnd() block)

    And no, vertex arrays aren't really THAT much faster to draw, but compared to immediate mode (glBegin(), glVertex() etc. crap) they're:
    1)In 99.9% of cases, more "clean" approach
    2)Really close to the REALLY fast way to draw (which TinyGL doesn't currently support, but will probably do some day)
    3)Not incompatible with OpenGL ES (OpenGL for mobile devices)

    While they are deprecated, VBO's aren't, and they are quite close to each other. As long as TinyGL doesn't support VBO (and shaders), we have no other choice but use deprecated functionality :-P

    Here is quite useful comparison between immediate mode and vertex arrays.

    Also, it's of course a VERY good idea to do your own DrawObject(struct MyObject *object); that will hide the boring details from most of the code.

    Few hints on writing OpenGL code with MorphOS:

    Immediate mode: glBegin(), glEnd(), glVertex() etc. - AVOID

    NOTE: You should NEVER use previously listed functionality!

    glColor() - Even if often used with immediate mode, this is ok for setting a constant color for further vertices to draw.
    glNormal(), glTexCoord() - As with glColor(), although it's quite rare to set these to a constant value.
    glTranslate(), glLoadMatrix(), glMultMatrix() etc. - These are the way to do transformations.
    glMatrixMode() - Used to change which matrix to apply changes to. Don't do glFrustum(), glOrtho(), gluPerspective() or similar each frame (unless its arguments change). In most cases,this belongs to your reshape function.

    NOTE: all of the previous functionality is deprecated, and done quite differently in "modern" OpenGL, which we cannot currently use on MorphOS.

    glEnableClientState(), glVertexPointer() (and equivalent for normals, texcoords, color), glDrawArrays(), glDrawElements() - While deprecated, the "idea" is generally the same (but used functions different) with modern OpenGL. Give OpenGL a pointer to elements, which it will draw. Of course you want to use VBO (upload the data to graphics ram) when possible. You can do this with few #ifdef's if you want to compile your code also for platforms that already support it.

    GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN - These are still around in every OpenGL (or OpenGL ES) implementation. Use freely.

    NOTE: all previous functionality (except immediate mode) works with OpenGL ES1. OpenGL ES2 uses shaders extensively, and it's not possible to write code that works both on current TinyGL and OpenGL ES2 without using lots of #ifdefs or similar, assuming you do something more complex than clear the screen with the specified color.

    GL_QUADS, GL_QUAD_STRIP, GL_POLYGON - AVOID. Deprecated, and missing from both OpenGL ES1 and ES2. Use indexed GL_TRIANGLES or GL_TRIANGLE_STRIP instead.

    -EDIT-
    This thread would be better called "non-MorphOS OpenGL how-not-to" :-P
  • »21.12.12 - 14:23
    Profile Visit Website
  • Paladin of the Pegasos
    Paladin of the Pegasos
    Jupp3
    Posts: 1193 from 2003/2/24
    From: Helsinki, Finland
    Hi,

    A while ago I wrote a simple OpenGL example program, which does thins the way I think they should be done with TinyGL (should also work with OpenGL ES)

    Hopefully someone finds it useful.

    The code can be found here
  • »26.08.13 - 14:13
    Profile Visit Website
  • Paladin of the Pegasos
    Paladin of the Pegasos
    Jupp3
    Posts: 1193 from 2003/2/24
    From: Helsinki, Finland
    Wrote a follow-up to the example that concentrates on error checking, available here.
  • »29.12.13 - 12:59
    Profile Visit Website