wojownik266 Temat założony przez niniejszego użytkownika |
[SFML OpenGl] Kamera nie chce się poruszać » 2025-08-14 13:42:00 Dlaczego kamera nie chce się poruszać? Co źle napisałem? Proszę o pomoc.. #include <SFML/Audio.hpp> #include <SFML/Graphics.hpp> #include <SFML/OpenGL.hpp> #include <GL/glu.h>
GLfloat angle = 0.05;
void rysujScene() { glBegin( GL_QUADS ); glColor3f( 1.0, 0.5, 0.0 ); glVertex3f( - 1.0f, 0.0f, - 1.0f ); glVertex3f( 1.0f, 0.0f, - 1.0f ); glVertex3f( 1.0f, 0.0f, 1.0f ); glVertex3f( - 1.0f, 0.0f, 1.0f ); glEnd(); } void rysujTlo() { glBegin( GL_QUADS ); glColor3f( 0.5, 0.5, 0.5 ); glVertex3f( - 10.0f, - 10.0f, - 1.0f ); glVertex3f( 10.0f, - 10.0f, - 1.0f ); glVertex3f( 10.0f, 10.0f, - 1.0f ); glVertex3f( - 10.0f, 10.0f, - 1.0f ); glEnd(); } int main() { sf::RenderWindow window( sf::VideoMode( { 800, 600 } ), "SFML window" ); GLfloat aspect = 800.0 / 600.0; GLfloat cam_x = 0.0, cam_y = 1.0, cam_z = - 5.0; glEnable( GL_DEPTH ); const sf::Texture texture( "tlo.jpg" ); sf::Sprite sprite( texture ); while( window.isOpen() ) { while( const std::optional event = window.pollEvent() ) { if( event->is < sf::Event::Closed >() ) window.close(); } if( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::Left ) ) { cam_x--; } else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::Right ) ) { cam_x++; } gluLookAt( cam_x, cam_y, cam_z, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 ); glViewport( 0, 0, 800, 600 ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45.0, aspect, 0.1, 100.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); rysujTlo(); rysujScene(); window.display(); } }
|
|
wojownik266 Temat założony przez niniejszego użytkownika |
» 2025-08-14 15:32:12 Problem rozwiązałem samodzielnie tworząc poniższy program... #include <SFML/Graphics.hpp> #include <SFML/OpenGL.hpp> #include <GL/glu.h>
void rysujPunkt() { glPointSize( 50 ); glBegin( GL_POINTS ); glColor3f( 1.0, 0.0, 0.5 ); glVertex3f( 0.0, 0.0, - 1.0 ); glEnd(); } int main() { sf::RenderWindow window( sf::VideoMode( { 800, 600 } ), "TEST KAMERY" ); GLfloat camX = 0.0, camY = 0.0, camZ = - 1.0; while( window.isOpen() ) { while( const std::optional event = window.pollEvent() ) { if( event->is < sf::Event::Closed >() ) { window.close(); } } if( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::Up ) ) { camY += 0.01; } else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::Down ) ) { camY -= 0.01; } else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::Left ) ) { camX -= 0.01; } else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::Right ) ) { camX += 0.01; } glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable( GL_DEPTH ); glLoadIdentity(); gluLookAt( camX, camY, camZ, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ); rysujPunkt(); window.display(); } return EXIT_SUCCESS; }
|
|
tBane |
» 2025-08-15 07:05:39 Czyli trzeba było ustawiać zawsze macierz kamery po glClear() a przed rysowaniem. Dzięki :-) |
|
« 1 » |