Questions about TinyGL (was TinyGL and glMaterialv)
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Hello,

    some little changes. I add fog to the scene and cleaned up the source.
    It's now looking like this on linux: landscape_fog_linux.png

    Next steps:
    - find out what's going wrong on mos
    - use Color arrays per vertex instead of materials (paint water blue, and so on, ...)
    - object groups
    - animation

    EDIT:
    I really could not find the error in my code.
    The vertex and normal arrays are ok, I also checked every gl function call with glGetError(), nothing.
    I also looked into the autodocs but I could not any usefull hint.
    The vertex and normal count for my landscape is 151686, could that be the problem?





    [ Edited by eliot 09.01.2017 - 04:11 ]
    regards
    eliot
  • »08.01.17 - 17:08
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    Jupp3
    Posts: 1193 from 2003/2/24
    From: Helsinki, Finland
    Quote:

    The vertex and normal count for my landscape is 151686, could that be the problem?

    As long as the max. value can be specified with the used index type (GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT), it should work. If not, I'd say that's a bug in GL implementation (unless there's some other bug elsewhere).

    But another question, how are you drawing your heightmap in general?

    Probably the most efficient way is to specify each point in map in the vertex array once, then have series of GL_TRIANGLE_STRIP arrays (in same VBO), that specify the vertex id's in triangles used in that particular row. Of course you also lose control over "which way quads are split to triangles" (splitting this conditionally is way more complex) - oh, and using GL_QUADS isn't useful either, basically you just pretend that OpenGL wouldn't draw 2 triangles instead (which it does).

    Then just do a simple for loop, and draw the rows you want. This way you can also only draw specific rows, which you probably want later, so you only draw specific range in front of the camera.

    Example:
    Vertex array (number specifies the order points are specified in)
    00 04 08
    01 05 09
    02 06 10
    03 07 11

    Index array:
    00, 04, 01, 05, 02, 06, 03, 07 (first row done),
    04, 08, 05, 09, 06, 10, 07, 11 (second row done)

    -EDIT-

    One generic tip for "I'm not getting the graphics I expected to" cases: Draw as GL_POINTS or GL_LINE_STRIP instead. That way, you will get some (wrong) graphics, even if triangles (should you have drawn as them) were facing backwards (and you've enabled bfc, like you should). Then just compare if you get vertices in locations you don't, when drawing with the "correct" primitive.

    [ Edited by Jupp3 10.01.2017 - 23:30 ]
  • »10.01.17 - 12:08
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Hello again,

    finally I found a solution for MorphOs.
    Screenshots:
    linux: landscape_linux_fog_working.png
    mos: landscape_mos_fog_missing.png

    And that's what I have done:
    1. I replaced std::vector by my own Array class (move away from stack to heap)
    That should be done anyway.
    2. Implemented splitting of 3d objects (vertex and normals arrays)
    3. Objects with a vertex count lesser than 4096 will rendered correctly on mos
    (any greater number will fail)

    Nice!

    But, while blending works well (transparent water), fog on mos fails.
    That is the code I am using:
    Code:

    glEnable(GL_FOG);
    glFogi(GL_FOG_MODE, GL_LINEAR);
    glFogf(GL_FOG_DENSITY, 1.0f);
    glFogf(GL_FOG_START, 0.f);
    glFogf(GL_FOG_END, range / 2.0f);
    glFogfv(GL_FOG_COLOR, scene->clearColor.rgba);


    I can remember that the guys of Wings Battlefield also had problems with glFog on mos.
    Sadly I do not know the solution.
    Any hints?
    regards
    eliot
  • »12.01.17 - 17:10
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    Jupp3
    Posts: 1193 from 2003/2/24
    From: Helsinki, Finland
    Quote:

    eliot wrote:
    I can remember that the guys of Wings Battlefield also had problems with glFog on mos.
    Sadly I do not know the solution.
    Any hints?


    There has been major rewrite in some parts of 3D acceleration (on some GPU's), which sadly also resulted in some previously working features becoming broken. Not sure, if fog was one of them (texture matrix is, at least)
  • »12.01.17 - 22:57
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    BSzili
    Posts: 559 from 2012/6/8
    From: Hungary
    GL_FOG stuff is not implemented in TinyGL.
    This is just like television, only you can see much further.
  • »13.01.17 - 06:20
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Quote:

    BSzili wrote:
    GL_FOG stuff is not implemented in TinyGL.


    Ok, what I can use instead?
    Or will it be implemented in near future?

    EDIT: Can somebody of the mods change this topic to a more general one like "Questions about TinyGL"?

    [ Edited by eliot 13.01.2017 - 06:42 ]
    regards
    eliot
  • »13.01.17 - 06:37
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    I am getting really crazy about using color arrays instead of glMaterial:

    Here is the code:

    Code:

    #ifdef __APPLE__

    #include <gl.h>
    #include <glu.h>
    #include <glut.h>

    #else
    #define GL_GLEXT_PROTOTYPES

    #include <GL/gl.h>
    #include <GL/glu.h>
    #include <GL/glut.h>

    #endif

    #include <stdio.h>

    static char *TITLE = "test_materials_vbos";

    static GLuint verticesId = 0;
    static GLuint normalsId = 0;
    static GLuint redId = 0;
    static GLuint greenId = 0;

    static GLfloat VERTICES[] = {0, 0, 0,
    1, 0, 0,
    1, 1, 0};

    static GLfloat NORMALS[] = {0, 0, 1,
    0, 0, 1,
    0, 0, 1};

    static GLfloat RED[] = {1, 0, 0, 1,
    1, 0, 0, 1,
    1, 0, 0, 1};

    static GLfloat GREEN[] = {0, 1, 0, 1,
    0, 1, 0, 1,
    0, 1, 0, 1};

    static void objects() {
    /* vertices */
    glGenBuffers(1, &verticesId);
    glBindBuffer(GL_ARRAY_BUFFER, verticesId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(VERTICES), VERTICES, GL_STATIC_DRAW);

    /* normals */
    glGenBuffers(1, &normalsId);
    glBindBuffer(GL_ARRAY_BUFFER, normalsId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(NORMALS), NORMALS, GL_STATIC_DRAW);

    /* red */
    glGenBuffers(1, &redId);
    glBindBuffer(GL_ARRAY_BUFFER, redId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(RED), RED, GL_STATIC_DRAW);

    /* red */
    glGenBuffers(1, &greenId);
    glBindBuffer(GL_ARRAY_BUFFER, greenId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(GREEN), GREEN, GL_STATIC_DRAW);

    }

    static void light() {
    GLfloat LP[] = {0, 0, 10, 1};
    GLfloat A[] = {0.1, 0.1, 0.1};
    GLfloat S[] = {0.5, 0.5, 0.5};
    GLfloat D[] = {0.5, 0.5, 0.5};

    glEnable(GL_LIGHT0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glLightfv(GL_LIGHT0, GL_POSITION, LP);
    glLightfv(GL_LIGHT0, GL_AMBIENT, A);
    glLightfv(GL_LIGHT0, GL_SPECULAR, S);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, D);
    }

    void init() {
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glEnable(GL_FRONT);
    glEnable(GL_LIGHTING);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT);

    glClearColor(0.f, 0.f, 0.f, 1.f);

    light();
    objects();
    }

    void reshape(int width, int height) {
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(65.0, (float) width / (float) height, 1.0, 100);
    }

    void display() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    gluLookAt(0, 0, 5,
    0, 0, 0,
    0, 1, 0);

    /* red triangle */
    {
    glPushMatrix();

    glTranslated(-1, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glBindBuffer(GL_ARRAY_BUFFER, verticesId);
    glVertexPointer(3, GL_FLOAT, 0, (void *) 0);

    glBindBuffer(GL_ARRAY_BUFFER, normalsId);
    glNormalPointer(GL_FLOAT, 0, (void *) 0);

    glBindBuffer(GL_ARRAY_BUFFER, redId);
    glColorPointer(4, GL_FLOAT, 0, (void *) 0);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    glPopMatrix();
    }

    /* green triangle */
    {
    glPushMatrix();

    glTranslated(1, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glBindBuffer(GL_ARRAY_BUFFER, verticesId);
    glVertexPointer(3, GL_FLOAT, 0, (void *) 0);

    glBindBuffer(GL_ARRAY_BUFFER, normalsId);
    glNormalPointer(GL_FLOAT, 0, (void *) 0);

    glBindBuffer(GL_ARRAY_BUFFER, greenId);
    glColorPointer(4, GL_FLOAT, 0, (void *) 0);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    glPopMatrix();
    }
    glutSwapBuffers();
    }

    int main(int argc, char **argv) {
    int window = 0;

    /* init glut */
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(0, 0);

    /* create window */
    window = glutCreateWindow(TITLE);

    /* set callbacks */
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);

    /* init gl, light and objects */
    init();

    printf("sizeof RED=%dn", sizeof(RED));

    /* enter main loop */
    glutMainLoop();

    /* destroy window */
    glutDestroyWindow(window);
    return 0;
    }



    and this is the result:
    ogl_colors.png

    There should be one red triangle and another one in green.
    I could not find the error yet.

    EDIT: The example is now ok.
    In my other code I have found the problem:
    A really simple class (Color) like this one:

    Code:

    struct s{

    float f[4];
    };


    It is 24 bytes long (reported by sizeof) but should be 16 (four time float).
    I do not know where the extra bytes are coming from, but I now know where to search.

    [ Edited by eliot 23.01.2017 - 14:46 ]
    regards
    eliot
  • »23.01.17 - 13:45
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Nice,

    cloring is now working (no glMaterial anymore). The Landscape generator can be parameterised
    (I am not a designer who can paint landscapes).

    Linux: linux_landscape_coloring.png
    Mos: mos_landscape_coloring.png

    Another question: currently I am using floats for rgba values. It would use less memory if I
    use chars instead of floats. Any disadvantages?

    Next to go: animations

    [ Edited by eliot 26.01.2017 - 19:17 ]
    regards
    eliot
  • »25.01.17 - 14:28
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Hello again,

    SDL1 is now working on all platforms. I am getting better keyboard and mouse events and
    fullscreen is also working. I also fixed lighting stuff (should look better now).

    Morphos with SDL:heightmap_sdl_mos.png

    I am focussing on learning Blender because I want to create some 3D objects like a helicopter, trees, buildings, ...



    [ Edited by eliot 25.02.2017 - 15:53 ]
    regards
    eliot
  • »25.02.17 - 15:41
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Is glGenerateMipmap not available on mos?

    Code:

    g++ -c lib/src/Renderer.cpp -std=c++11 -noixemul -I lib/include
    lib/src/Renderer.cpp: In member function 'void exdevgfx::Renderer::initObject(exdevgfx::Object&)':
    lib/src/Renderer.cpp:197:35: error: 'glGenerateMipmap' was not declared in this scope
    glGenerateMipmap(GL_TEXTURE_2D);
    regards
    eliot
  • »15.04.17 - 06:50
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    BSzili
    Posts: 559 from 2012/6/8
    From: Hungary
    Quote:

    eliot wrote:
    Is glGenerateMipmap not available on mos?

    Code:

    g++ -c lib/src/Renderer.cpp -std=c++11 -noixemul -I lib/include
    lib/src/Renderer.cpp: In member function 'void exdevgfx::Renderer::initObject(exdevgfx::Object&)':
    lib/src/Renderer.cpp:197:35: error: 'glGenerateMipmap' was not declared in this scope
    glGenerateMipmap(GL_TEXTURE_2D);



    That's an OpenGL4 function, so no. You can use gluBuild2DMipmaps instead.
    This is just like television, only you can see much further.
  • »15.04.17 - 17:33
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Hi,

    thx for your help. I tried it with gluBuild2DMipmaps like this:
    Code:

    glGenTextures(1, &o.textureId);
    glBindTexture(GL_TEXTURE_2D, o.textureId);
    glTexImage2D(GL_TEXTURE_2D,
    0,
    GL_RGBA,
    (GLsizei) o.texture->width,
    (GLsizei) o.texture->height,
    0,
    GL_RGBA,
    GL_UNSIGNED_BYTE,
    o.texture->data);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    #ifdef __MORPHOS__
    gluBuild2DMipmaps(GL_TEXTURE_2D,
    4,
    (GLsizei)o.texture->width,
    (GLsizei)o.texture->height,
    GL_RGBA,
    GL_UNSIGNED_BYTE,
    o.texture->data);
    #else

    glGenerateMipmap(GL_TEXTURE_2D);
    #endif


    But the result looks ugly on MorphOs. The Linear Filtering does not seem to work.
    Here are screenshots from MorphOs and Linux:
    Mos:
    mos_mipmap.png
    Linux:
    linux_mipmap.png

    Do you have any idea what's going wrong?

    [ Edited by eliot 26.04.2017 - 16:49 ]
    regards
    eliot
  • »26.04.17 - 15:48
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Hmm,
    hello again,

    things are moving really slowly forward, but the MorphOs build is working again :)
    The landscape is now divided into smaller objects, wavefront loader and animations are
    working.

    test_heightmap_working_mos.png
    test_first_person_mos_working.png

    Small steps, but I am still alive, ...

    [ Editiert durch eliot 24.12.2018 - 13:09 ]
    regards
    eliot
  • »24.12.18 - 13:04
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Thanks to a friend who knows Blender we've got a helicopter :)

    Video Helicopter

    [ Editiert durch eliot 31.12.2018 - 12:52 ]
    regards
    eliot
  • »31.12.18 - 12:52
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Hello,

    just another small update:

    - reworked the translation, rotation, animation system
    - sky boxes
    - texture animation
    - implemented first helicopter controller
    - many small changes inside

    Some videos:
    Helicopter Video
    First Person Video

    Next steps:
    - test on MorphOs 3.12 with new SDK and Gcc 7
    - resize the helicopter (it's much to big compared to the landscape)
    - collision detection


    [ Edited by eliot 12.10.2019 - 22:09 ]
    regards
    eliot
  • »12.10.19 - 15:08
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 564 from 2004/4/15
    Hello,

    I just tested helicopter demo and first person demo on MorphOs 3.12 with the new SDK.
    Everything seems to be fine and worked as expected.
    I used the gcc/g++ 7.4.0 with O3 (on Linux I am using the same compiler so this was my first choice).

    Screenshots:
    helicopter_mos_20191016.png
    first_person_mos_20191016.png

    Edit:
    Just one small remark: gfx memory on mac mini slient upgrade gets really low when using triple buffer
    and having open some screens for browser, flow studio, etc.
    So the script for building the cross compilation setup is really appreciated.

    [ Edited by eliot 16.10.2019 - 12:21 ]
    regards
    eliot
  • »16.10.19 - 11:18
    Profile
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 451 from 2003/7/25
    From: Wroclaw/Poland
    Good to know, you haven't resigned MorphOS support. I hope you will finish the production. 👍
  • »16.10.19 - 18:40
    Profile Visit Website