I'm currently having two issues, and I think that they are related to each other.
1st, the SFML window I create does not draw/display anything until I move the mouse over it.
Second, whenever I move the mouse, my openGL primitives get both smaller and closer together-- as long as the mouse is moving (any direction, and INSIDE the SFML window) until they disappear completely. I'll post the relevant code here, because I am currently stumped and I have no idea what to google for on this issue.
///////////////////////////////////
/// Main starts the program,
/// creates a GameManager and
/// has it loop until completion
///////////////////////////////////
int main(int argc, char** argv)
{
//constructor game manager and start looping
GameManager Manager("Template");
Manager.Loop();
}
GameManager::GameManager(string title)
{
//the dimentions of the window
int size[2] = {800, 600} ;
//creates the game window, sized to the two elements of the array declared above
window.Create(sf::VideoMode(size[0],size[1]), title);
this->initGL();
this->resize(size[0], size[1]);
}
GameManager::~GameManager(void)
{
}
const sf::Input& GameManager::GetInput()
{
return window.GetInput();
}
void GameManager::Loop()
{
//constantly loop through the window
while(window.IsOpened())
{
//go through the event processing loop
sf::Event Event;
while(window.GetEvent(Event))
{
//process event based on type
switch(Event.Type)
{
//resize if resized
case sf::Event::Resized:
resize(Event.Size.Width, Event.Size.Height);
break;
//close if closed
case sf::Event::Closed:
window.Close();
break;
}
this->update();
this->draw();
window.Display();
}
}
}
void GameManager::draw()
{
//clear the screen
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
gluLookAt(0,0,1, 0,0,0, 0,1,0);
//viewport code here
//////////////////////
//////////////////////
//////////////////////
///end viewport code
//Drawing code here
glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
//for demo purposes, we draw a triangle
glPointSize(100);
glBegin(GL_TRIANGLES);
{
glVertex2f(-1,0);
glVertex2f(1,0);
glVertex2f(0,1);
}
glEnd();
//end drawing code
glFlush();
}
void GameManager::update()
{
}
void GameManager::initGL()
{
glClearColor(0,0,1,0);
glColor3f(0,1,0);
}
void GameManager::resize(float w, float h)
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, w /h, 1, 200);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,5, 0,0,0, 0,1,0);
}
class GameManager
{
public:
//////////////////
/// Creates the game window
/// And calls the resize method to properly set the window attributes and glViewport
/// \param The title of the game's window
//////////////////
GameManager(string title);
///////////////////
///
//////////////////
~GameManager(void);
//////////////////
/// Has the GameManager loop through the window cycle,
/// as well as updating and drawing stuff
//////////////////
void Loop();
///////////////////////////
/// Gets a reference to the window's input struct
///////////////////////////
const sf::Input& GetInput();
private:
////////////////////////
/// The render window
////////////////////////
sf::RenderWindow window;
//////////////////
/// The portion of the game currently running.
/// IE: MainMenu, OptionsMenu, etc
//////////////////
GameState state;
///////////////
/// Initializes the openGL states
//////////////
void initGL();
/////////////
/// Draws the game
/////////////
void draw();
////////////////
/// Updates everythign in need of updating
///////////////
void update();
///////////////
/// Resizes the window
///////////////
void resize(float w, float h);
};
The general gist is this:
Manager creates window. Manager updates and draws window repeatedly. Whenever the mouse is moved, the primitives (the vertex2f calls) get closer to the origin, and smaller, until they disappear completely.
Any help would be AMAZING.
I have tried:
[list=]
removing, moving, and in general experimenting with the commented out calls to glLoadIdentity() in the draw method.
debugging. The code stays in these 3 files, plus of course the openGL ones which I cannot see in VS, the entire time.
Changing the primitives from GL_POINTS to GL_LINES, and GL_TRIANGLES.
Removing GL_FLUSH.
[/list]