CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2014
    Posts
    2

    Beginner - Impossible to Draw a simple Triangle with OpenGL

    Hello,

    First of all, sorry for this newbie thread, but I'm encountering problems to draw a simple triangle with SDL and OpenGL.

    My IDE is Code::Blocks.
    In debug mode, there is no Error/warning, the window is corretly open but nothing is showed inside.
    Like no OpenGL commands are read...

    Here is my little C++ program, Can you help me to figure out where is the problem ? thx

    #include <SDL2/SDL.h>
    #include <GL/gl.h>
    #include <GL/glu.h>

    int main(int argc, char ** argv) {
    SDL_Window* mainWindow = SDL_CreateWindow(
    "OpenGL Triangle",
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    640,
    480,
    SDL_WINDOW_OPENGL
    );

    bool continuer = true;

    SDL_Event event;

    while (continuer) {
    SDL_WaitEvent(&event);
    switch(event.type) {
    case SDL_QUIT:
    continuer = false;
    }

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
    glColor3ub(255,0,0);
    glVertex2d(-0.75,-0.75);
    glColor3ub(0,255,0);
    glVertex2d(0,0.75);
    glColor3ub(0,0,255);
    glVertex2d(0.75,-0.75);
    glEnd();

    glFlush();

    SDL_GL_SwapWindow(mainWindow);
    }

    SDL_Quit();

    return 0;
    }

  2. #2
    Join Date
    Feb 2014
    Posts
    2

    Re: Beginner - Impossible to Draw a simple Triangle with OpenGL

    I tried to figure it out on my own but still stuck.

    I turned the Build Target to Console in order to view "Cout"

    1. I tried to check OpenGL commands by adding this before "glBegin"

    glEnable(GL_TEXTURE_2D);
    if (glIsEnabled(GL_TEXTURE_2D)) {
    cout << "OK\n";
    }
    else {
    cout << "NOK\n";
    }

    With this, I get "NOK" after the SDL window openning.

    2. After, I tried to get the GL flag error by adding before glBegin and also between glBegin/glEnd :

    cout << "GL Flag Error : " << glGetError() << "\n";

    With this, I get a 1282 error flag which refer to INVALID_OPERATION

    From some another forum, some say that it's du to an error between glBegin/glEnd, but for me I don't see any error (hope so)

    3. Finally, I tried to retreive the OpenGL Version by adding :

    const unsigned char* glVer = glGetString(GL_VERSION);
    cout << glVer << "\n";


    No build error, but the program stucks at this line...

    Please help me !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured