After two hours, I managed to trim it down and isolate the problem while keeping the code testable.
The cube rotates fine after removing this:
App.pushGLStates();
App.draw(idleUp);
App.popGLStates();
If I only remove the push and pop state functions, then the cube doesn't show up.
Full complete... minimal... working code:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <GL/glew.h>
#include <SFML/OpenGL.hpp>
#include <GL/glu.h>
#define M_PI 3.14159265358979323846
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
void NextSprite(sf::Sprite &Sprite, int SpriteSizeY, int rectHorizontal, int rectVertical);
int InitGL() // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 220.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
return true; // Initialization Went OK
}
void ResizeGLScene(int width, int height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,1000.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
int main()
{
// Create the main rendering window
sf::ContextSettings settings;
settings.depthBits = 32;
settings.stencilBits = 8;
settings.antialiasingLevel = 8;
settings.majorVersion = 3;
settings.minorVersion = 0;
sf::RenderWindow App(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, settings);
App.setVerticalSyncEnabled(true);
ResizeGLScene(App.getSize().x, App.getSize().y);
InitGL();
// Load the sprite image from a file
sf::Texture IdleUp;
if (!IdleUp.loadFromFile("idleUp.png"))
{
return EXIT_FAILURE;
}
sf::Sprite idleUp(IdleUp);
idleUp.setPosition(50, 100);
bool running = true;
while (running == true)
{
// Process events
sf::Event Event;
while (App.pollEvent(Event))
{
// Close window : exit
if (Event.type == sf::Event::Closed)
{
running = false;
}
else if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
{
running = false;
}
else if (Event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
glViewport(0, 0, Event.size.width, Event.size.height);
}
}
// Clear screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static float angle = 0.0f;
//DrawGLScene();
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f, -260.0f);
glRotatef(angle, 0.0f, 1.0f, 1.0f); // Move Left 1.5 Units And Into The Screen 6.0
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);
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);
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);
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);
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);
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();
angle += 0.5f;
App.pushGLStates();
App.draw(idleUp);
App.popGLStates();
// Display window contents on screen
App.display();
}
return EXIT_SUCCESS;
}