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

Author Topic: Making a Sandbox for learning OpenGL  (Read 2455 times)

0 Members and 2 Guests are viewing this topic.

manasij7479

  • Newbie
  • *
  • Posts: 7
    • View Profile
Making a Sandbox for learning OpenGL
« on: September 03, 2011, 02:53:40 am »
Hello (...)
I decided to learn sfml and OpenGL together (instead of going with glut)
The OpenGL book I'm following shows how to use glut to set up things like double buffering. (How much it is handled automatically?)
I wrote the following program as a base on which I'd be applying everything I learn about OpenGL in near future. (changing the initialize() and draw()  when necessary.)
Could anyone of you review it to see if anything else is necessary ?
Code: [Select]

#include<iostream>
#include<SFML/Window.hpp>
#include<GL/gl.h>
#include<GL/glu.h>

using namespace sf;

void draw(int x);
void initialize();

int main()
{
    Window app(VideoMode(320,240,32),"Manasij");
    app.UseVerticalSync(true);
    initialize();
    int x(0);
    bool running(1);
    while(running)
    {
        Event event;
        while(app.GetEvent(event))
        {
            if(event.Type == Event::Closed)
                running = false;
            if(event.Type == Event::KeyPressed && event.Key.Code == Key::P) //Pause
                std::cin.get();
        }
       
        draw(x++);
             
        app.Display();
    }
    return 0;
}

void draw(int x)
{
    glClear ( GL_COLOR_BUFFER_BIT );
    glBegin(GL_POLYGON);

    glVertex3i(40+x%100,200,0);
    glVertex3i(80,200,0);
    glVertex3i(80,100,0);
    glEnd();
   
    glFlush();
}

void initialize()
{
    glClearColor ( 1.0, 1.0,1.0, 0.0 );
    glColor3f(0.0f, 0.0f,0.0f);

    glPointSize(1.0);

    glMatrixMode ( GL_PROJECTION );
    glLoadIdentity();
    gluOrtho2D ( 0.0, (GLdouble)320, 0.0, (GLdouble)240 );
}


DeroldClifford

  • Newbie
  • *
  • Posts: 2
    • View Profile
Making a Sandbox for learning OpenGL
« Reply #1 on: September 07, 2011, 03:35:03 am »
Howdy, I'm playing around with the same stuff.

First of all you do not need to include the openGL headers, the window header does it for you and it does it in a way that is cross platform.

like:
Code: [Select]
#include <SFML/window.hpp>

however in my environment I need to do it like so:
Code: [Select]
#include "SFML/window.hpp"
:)
small thing but they are interpreted differently for me.

ok,,,, as for the rest it look OK to me.  But on a side note I have been using
Code: [Select]
#include "SFML/Grapics.hpp"
instead, this allows me to use the text functions for displaying stuff that helps me debug the program later.
Barely a beginner, so please correct me, not burn me.