From 8bf954dd97493facdaccc56e60cc65ea22a0fe4a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 6 Mar 2012 22:47:16 -0500 Subject: [PATCH] add opengl --- Makefile | 4 +-- opengl.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 opengl.cpp diff --git a/Makefile b/Makefile index 58c4102..8342f65 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ CXX := $(PREFIX)-g++ LD := $(PREFIX)-ld CPPFLAGS := -I$(SFML_DIR)/include CXXFLAGS := -mwindows -LDFLAGS := -L$(SFML_DIR)/lib -lsfml-system -lsfml-window -static-libstdc++ -static-libgcc -mwindows +LDFLAGS := -L$(SFML_DIR)/lib -lsfml-system -lsfml-window -lopengl32 -lglu32 -static-libstdc++ -static-libgcc -mwindows -all: clock window events dlls +all: clock window events opengl dlls %: %.cpp $(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) $^ $(LDFLAGS) diff --git a/opengl.cpp b/opengl.cpp new file mode 100644 index 0000000..185af7f --- /dev/null +++ b/opengl.cpp @@ -0,0 +1,87 @@ + +#include + +int main() +{ + sf::Clock Clock; + sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL"); + App.UseVerticalSync(true); + App.SetActive(); + + // Set color and depth clear value + glClearDepth(1.f); + glClearColor(0.f, 0.f, 0.f, 0.f); + + // Enable Z-buffer read and write + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); + + // Setup a perspective projection + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(90.f, 1.f, 1.f, 500.f); + + while (App.IsOpened()) + { + sf::Event Event; + while (App.GetEvent(Event)) + { + if (Event.Type == sf::Event::Closed) + App.Close(); + + if ( (Event.Type == sf::Event::KeyPressed) + && (Event.Key.Code == sf::Key::Escape) ) + App.Close(); + + if (Event.Type == sf::Event::Resized) + glViewport(0, 0, Event.Size.Width, Event.Size.Height); + + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.f, 0.f, -200.f); + glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f); + glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f); + glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f); + + 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(); + + App.Display(); + } + + return EXIT_SUCCESS; +}