0

I am trying to develop a working EFIS display written in C++, OpenGL and the X-Plane SDK for an aircraft in X-Plane. I do not have very much experience with C++ and OpenGL. However, I do know X-Plane fairly well and I know how to use the X-Plane data for moving each element. What I do not know is how to code the EFIS display to draw all of the elements in an efficient way. I only know the very basics of drawing an OpenGL GL_QUAD and binding a texture to it however this seems to be a very low-level way of doing things.

What I would like to be able to do is create the GUI for the EFIS in a more efficient way as there are a lot of texture elements that need to be drawn.

This is an example of what I would like to build for X-Plane:

enter image description here

Here is the code I have currently written that loads in 1 image texture and binds it to a GL_QUAD.

    static int my_draw_tex(
    XPLMDrawingPhase     inPhase,
    int                  inIsBefore,
    void* inRefcon)
{


    // Note: if the tex size is not changing, glTexSubImage2D is faster than glTexImage2D.

    // The drawing part.
    XPLMSetGraphicsState(
        0,        // No fog, equivalent to glDisable(GL_FOG);
        1,        // One texture, equivalent to glEnable(GL_TEXTURE_2D);
        0,        // No lighting, equivalent to glDisable(GL_LIGHT0);
        0,        // No alpha testing, e.g glDisable(GL_ALPHA_TEST);
        1,        // Use alpha blending, e.g. glEnable(GL_BLEND);
        0,        // No depth read, e.g. glDisable(GL_DEPTH_TEST);
        0);        // No depth write, e.g. glDepthMask(GL_FALSE);


    //---------------------------------------------- HORIZON -----------------------------------------//


    glPushMatrix();

    // Bind the Texture
    XPLMBindTexture2d(texName[HORIZON], 0);
    glColor3f(1, 1, 1);
    glBegin(GL_QUADS);

        // Initial coordinates for the horizon background

    int arry[] = { 838, 465, 838, 2915, 2154, 2915, 2154 ,465 };      

    // Coordinates for the image
    glTexCoord2f(0, 0);       glVertex2f(arry[0], arry[1]); 
    glTexCoord2f(0, 1);       glVertex2f(arry[2], arry[3]); 
    glTexCoord2f(1, 1);       glVertex2f(arry[4], arry[5]);  
    glTexCoord2f(1, 0);       glVertex2f(arry[6], arry[7]); 
    glEnd();


    /*glDisable(GL_SCISSOR_TEST);*/

    glPopMatrix();


    return 1;

}

If someone could help with this, I would greatly appreciate it.

Spektre
  • 45,598
  • 10
  • 100
  • 347
  • this is old GL api which is slow if too many vertices. You can use VBO on top of this which get rid of all the `glBegin ... glEnd` stuf and use single `glDraw` call for VBO instead which is many times faster as the true bottleneck is not rendering itself but `glCalls` overhead once you familiar with VBO you can move even further into new GL api using shaders see [complete GL+GLSL+VAO/VBO C++ example](https://stackoverflow.com/a/31913542/2521214) but you should also look into some good OpenGL tutorial. You should also google [Blending/transparency](https://stackoverflow.com/a/37783085/2521214) – Spektre May 22 '22 at 05:35

0 Answers0