Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Overlaying things onto OpenGL  (Read 1466 times)

0 Members and 1 Guest are viewing this topic.

Meelo

  • Newbie
  • *
  • Posts: 1
    • View Profile
Overlaying things onto OpenGL
« on: May 26, 2010, 12:46:48 am »
I'm new to SFML, and I've been trying to figure out how to have an interface drawn on top of a 3D image. I can do either individually, fine, but overlaying anything onto OpenGL is beyond me. (Some code that's a fairly simple case of this:
Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

bool setupGL(){
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f};
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
return true;
}

int main()
{
    // Create main window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML OpenGL", sf::Style::Close);
sf::Shape Polygon;
Polygon.AddPoint(0, -50,  sf::Color(255, 0, 0),     sf::Color(0, 128, 128));
Polygon.AddPoint(50, 0,   sf::Color(255, 85, 85),   sf::Color(0, 128, 128));
Polygon.AddPoint(50, 50,  sf::Color(255, 170, 170), sf::Color(0, 128, 128));
Polygon.AddPoint(0, 100,  sf::Color(255, 255, 255), sf::Color(0, 128, 128));
Polygon.AddPoint(-50, 50, sf::Color(255, 170, 170), sf::Color(0, 128, 128));
Polygon.AddPoint(-50, 0,  sf::Color(255, 85, 85),   sf::Color(0, 128, 128));

App.SetFramerateLimit(60);
sf::Clock timer;
setupGL();
int face = 0;
int window_x = 800;
int window_y = 600;
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
if (Event.Type == sf::Event::Resized){
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
window_x = Event.Size.Width;
window_y = Event.Size.Height;
}

        }

        //App.Clear();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(timer.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(timer.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(timer.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
glBegin(GL_QUADS);

    glVertex3f(-50.f, -50.f, -50.f);
    glVertex3f(-50.f,  50.f, -50.f);
    glVertex3f( 50.f,  50.f, -50.f);
    glVertex3f( 50.f, -50.f, -50.f);

glEnd();
App.Draw(Polygon);
        App.Display();
    }

    return EXIT_SUCCESS;
}


What's the best way to do this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Overlaying things onto OpenGL
« Reply #1 on: May 26, 2010, 09:37:22 am »
Call App.PreserveOpenGLStates(true) once at the beginning of your program.

You should have a look at the OpenGL sample from the SDK, it does exactly what you want.
Laurent Gomila - SFML developer

 

anything