• Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    eliot
    Posts: 508 from 2004/4/15
    Thx for your answer.
    You absolutely right with the stride values. They are wrong (I used interleaving before but throw it away later).
    Besides there were two more "errors" in my code:

    1. Static Initializer Problem
    I am using static class member in Color.cpp and Material.cpp for default colors and materials.
    Material used default colors. The ordering on MorphOs was wrong but worked on Linux/MacOs.
    I fixed the issue in my code by not using default colors for default materials (another workaround would
    be to put Materials and Color implementation into the same compile unit).

    2. MorpgOs Opengl imlpementation needs to call glDisableClientState after every glDrawArrays
    Do not know why, but without it does not render anything.

    So the init code looks like that:
    Code:

    // vertices
    glGenBuffers(1, &o.vertexId);
    glBindBuffer(GL_ARRAY_BUFFER, o.vertexId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * o.vertices.size(), o.vertices.data(), GL_STATIC_DRAW);
    // normals
    glGenBuffers(1, &o.normalId);
    glBindBuffer(GL_ARRAY_BUFFER, o.normalId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * o.normals.size(), o.normals.data(), GL_STATIC_DRAW);


    and the rendering code:
    Code:

    glPushMatrix();

    glTranslated(t.translation.x, t.translation.y, t.translation.z);
    glRotated(t.rotation.x, 1, 0, 0);
    glRotated(t.rotation.y, 0, 1, 0);
    glRotated(t.rotation.z, 0, 0, 1);

    setMaterial(m);

    glBindBuffer(GL_ARRAY_BUFFER, o.vertexId);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, NULL);

    glBindBuffer(GL_ARRAY_BUFFER, o.normalId);
    glEnableClientState(GL_NORMAL_ARRAY);
    glNormalPointer(GL_FLOAT, 0, NULL);

    glDrawArrays(GL_TRIANGLES, 0, o.vertices.size());

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);

    glPopMatrix();


    These things will be done next:
    1. obj loader (import objects from blender)
    2. hight maps (based on pgms)
    3. flight controller
    4. throw away glut and use x11/mui directly (needs really to be done for better mouse/keyboard input)
    regards
    eliot
  • »02.01.17 - 15:45
    Profile