Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: [SFML/C++] Simple OpenGL Triangle

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    9

    Angry [SFML/C++] Simple OpenGL Triangle

    Hi!
    I'm using SFML, which uses OpenGL, and have found that a simple OpenGL triangle will only display under weird circumstances. Here's the code for the triangle:

    Code :
    void drawGL() {
    	std::cout<<"GL\n";
    	glBegin(GL_TRIANGLES);
    		glVertex2f(0.0f,0.5);
    		glVertex2f(-0.5f,-0.5f);
    		glVertex2f(0.5f,-0.5f);
    	glEnd();
    }

    This is the part of my window loops that concerns the OpenGL portion of the window:

    Code :
    window.clear();
    		if(state==1) {
    			drawInterfaces();
    		}
    		else {
    			drawGL();
    		}
    		window.display();

    drawInterfaces() is a function to display some 2D sprites. state is changed to 2 when I want the triangle to be displayed.

    This will only work if I remove the state system all together and just allow drawGL() to display by its own. Example: the above window portion will NOT work. This, however, WILL work.

    Code :
    window.clear();
    drawGL();
    window.display();

    I'm pretty sure this isn't SFML's fault because I can still initialize all of my sprites, load the images and put them into sprites before calling drawGL() and it works.

    Thanks for reading!

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    10
    Is your state system being updated properly?

    For example, during the loop are you using something like getState(), or checkState()?

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    9
    What I mean is, I have an integer to see whether or not the program should draw the interface or OpenGL. At the moment it will draw the 2D interface to begin with, but when the state is changed I get a black background with no triangle.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    10
    I tried to recreate your problem and couldn't. Could you post your whole loop please?

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    9
    Nothing else in the loop really concerns the problem. The only relevant information to give you is that before I start the window's frame loop, I initialize some SFML sprites and textures. This doesn't seem to effect anything when I start the loop with drawGL(), though. I think this is my fault. I think I'll just do the usual "stare at the code until it shows itself" technique.

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    10
    Try and put your state into a switch statement and see if that solves it

    Code :
    switch(state){
    case 1:
    drawMenu() // Whatever you called it
    break;
    case 2:
    drawTriangle() // Draw the triangle
    break;
    }

Posting Permissions

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