I got a problem with this Code ...
why does he just draw the back site of the cube ??
thx 4 help guys :D
#include<SFML/OpenGL.hpp>
#include<SFML/Graphics.hpp>
#include<iostream>
#define ScW 800
#define ScH 600
void display();
void specialKeys();
sf::RenderWindow window;
double rotate_y=0;
double rotate_x=0;
void display()
{
// Clear screen and Z-buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Rotate when user changes rotate_x and rotate_y
// glRotatef(rotate_x, 1.0, 0.0, 0.0 );
//glRotatef(rotate_y, 0.0, 1.0, 0.0 );
//Multi-colored side - FRONT
glBegin(GL_QUADS);
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( 0.5, -0.5, -0.5 ); // P1 is red
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( 0.5, 0.5, -0.5 ); // P2 is green
glColor3f( 0.0, 0.0, 1.0 );
glVertex3f( -0.5, 0.5, -0.5 ); // P3 is blue
glColor3f( 1.0, 0.0, 1.0 );
glVertex3f( -0.5, -0.5, -0.5 ); // P4 is purple
// White side - BACK
glColor3f( 1.0, 1.0, 1.0 );
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
// Purple side - RIGHT
glColor3f( 1.0, 0.0, 1.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
// Green side - LEFT
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
// Blue side - TOP
glColor3f( 0.0, 0.0, 1.0 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
// Red side - BOTTOM
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
glEnd();
}
void specialKeys()
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
rotate_y += 5;
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
rotate_y -= 5;
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
rotate_x += 5;
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
rotate_x -= 5;
}
int main()
{
bool run = 1;
sf::RenderWindow window (sf::VideoMode(ScW, ScH), "CUBE");
glClearColor(0,0,0,0);
glViewport(0,0,ScW,ScH);
glEnable(GL_DEPTH_TEST);
while(run)
{
display();
specialKeys();
window.display();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::X))
run = 0;
}
return 0;
}
Last edited on