Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: hyperturtle/gg.cpp
base: aad0cfaf4b
...
head fork: hyperturtle/gg.cpp
compare: 341ab9444a
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
3  .gitignore
@@ -0,0 +1,3 @@
+build/assets
+build/*.exe
+temp/
View
19 Makefile
@@ -0,0 +1,19 @@
+CPP = g++
+RM = rm
+MKDIR = mkdir
+CPPFLAGS = -I/mingw/SFML-1.6/include -I/mingw/include/ -std=gnu++0x
+LDFLAGS = -static-libstdc++ -static-libgcc -lsfml-audio-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lmingw32 -lopengl32 -lglu32 -L/mingw/SFML-1.6/lib -L/mingw/lib -O0 -Wall -fmessage-length=0
+OBJDIR = temp/
+
+all: build/main.exe
+
+build/main.exe: main.cpp gg.hpp $(OBJDIR)/gg.o Makefile
+ $(CPP) -o build/main.exe main.cpp $(OBJDIR)/gg.o $(LDFLAGS) $(CPPFLAGS)
+
+$(OBJDIR)/gg.o: gg.cpp gg.hpp Makefile
+ test -d $(OBJDIR) || $(MKDIR) $(OBJDIR)
+ $(CPP) -o $(OBJDIR)/gg.o gg.cpp -c $(LDFLAGS) $(CPPFLAGS)
+
+clean:
+ test -d $(OBJDIR) || $(RM) -rf $(OBJDIR)
+ $(RM) build/main.exe
View
BIN  build/libsndfile-1.dll
Binary file not shown
View
BIN  build/openal32.dll
Binary file not shown
View
65 gg.cpp
@@ -0,0 +1,65 @@
+#include "gg.hpp"
+
+GG::GG() {
+ Clock = new sf::Clock();
+ srand ( Clock->GetElapsedTime() );
+}
+
+GG::~GG(){
+ delete App;
+ delete Clock;
+}
+
+void GG::start(int width, int height) {
+
+ this->width = width;
+ this->height = height;
+ sf::WindowSettings Settings;
+ Settings.DepthBits = 24; // Request a 24 bits depth buffer
+ Settings.StencilBits = 8; // Request a 8 bits stencil buffer
+ Settings.AntialiasingLevel = 0; // Request 2 levels of antialiasing
+ App = new sf::Window(sf::VideoMode(width, height, 32), "SFML OpenGL", sf::Style::Close, Settings);
+
+
+ init();
+
+
+
+ glClearDepth(1.0f);
+ glViewport(0, 0, this->width, this->height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, this->width, this->height, 0, 1, -1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glEnable(GL_TEXTURE_2D);
+
+ glEnable (GL_BLEND);
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+
+ float time_now;
+ while (App->IsOpened()) {
+ sf::Event Event;
+ while (App->GetEvent(Event)) {
+ if (Event.Type == sf::Event::Closed)
+ App->Close();
+ }
+
+ time_now = Clock->GetElapsedTime();
+ if(time_now > 1.0f/60.0f) {
+
+ loop();
+
+ App->Display();
+ Clock->Reset();
+ } else {
+ sf::Sleep(1.0f/60.0f - time_now);
+ }
+ }
+
+ time_now = Clock->GetElapsedTime();
+}
View
32 gg.hpp
@@ -0,0 +1,32 @@
+#ifndef __GG__HPP__
+#define __GG__HPP__
+
+#include <SFML/Window.hpp>
+#include <SFML/Graphics.hpp>
+#include <SFML/Audio.hpp>
+
+class GG {
+ private:
+ sf::Window * App;
+ sf::Clock * Clock;
+
+ int width;
+ int height;
+
+ float prev_frame_clock;
+
+ public:
+ GG();
+ virtual ~GG();
+
+
+ void start(int width=800, int height=600);
+
+ virtual void init() = 0;
+ virtual void loop() = 0;
+
+ void addSound();
+ void playSound();
+};
+
+#endif
View
102 main.cpp
@@ -0,0 +1,102 @@
+#include "gg.hpp"
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+float x = 400.0f;
+float y = 300.0f;
+float vx = 0.0f;
+float vy = 0.0f;
+
+char words1[] = "ABCDEFGHIJKLOPQRSTUVWXYZ";
+char words2[] = "0123456789";
+char words3[] = "HELLO!";
+char words4[] = "WORLD?";
+
+void drawstring(const char *word, float x, float y, float s){
+ //float offset = s*0.8f;
+ float letter_x;
+ float letter_y;
+ float offset_x;
+ float offset_y;
+ for(unsigned int i = 0; i < strlen(word); i ++){
+ letter_x = (((int)word[i] - 32)%32) * 0.03125f;
+ letter_y = (((int)word[i] - 32)/32) * 0.03125f;
+ offset_x = x + i*s*1.142857143f;
+ offset_y = y;
+ glTexCoord2f(letter_x , letter_y ); glVertex3f(offset_x, offset_y, 0);
+ glTexCoord2f(letter_x + 0.03125f - 0.00390625f, letter_y ); glVertex3f(offset_x+s, offset_y, 0);
+ glTexCoord2f(letter_x + 0.03125f - 0.00390625f, letter_y + 0.03125f - 0.00390625f); glVertex3f(offset_x+s, offset_y+s, 0);
+ glTexCoord2f(letter_x , letter_y + 0.03125f - 0.00390625f); glVertex3f(offset_x, offset_y+s, 0);
+ }
+}
+
+class gg: public GG {
+ void init() {
+ sf::Image Image;
+ if (!Image.LoadFromFile("assets/sprite.png"))
+ {
+ return;
+ }
+
+ sf::SoundBuffer Buffer;
+ if (!Buffer.LoadFromFile("assets/test.wav"))
+ {
+ return;
+ }
+
+ sf::Sound Sound;
+ Sound.SetBuffer(Buffer);
+
+ //Sound.Play();
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, Image.GetWidth(),
+ Image.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
+ Image.GetPixelsPtr());
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+ glClearColor(0.9f, 0.9f, 0.9f, 1);
+ }
+ void loop() {
+ vx *= 0.999f;
+ vx += float(rand()) / float(RAND_MAX) - 0.5f;
+ x += vx;
+ vy *= 0.999f;
+ vy += float(rand()) / float(RAND_MAX) - 0.5f;
+ y += vy;
+ if (x < 0.0f || x > 800.0f || y < 0.0f || y > 600.0f) {
+ x = 400.0f;
+ y = 300.0f;
+ vx = 0.0f;
+ vy = 0.0f;
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glBegin(GL_QUADS);
+
+ glColor4f(0.1f,0.1f,0.1f,1);
+ drawstring(words1, x, y, 21);
+ drawstring(words2, y, x, 28);
+ drawstring(words3, 800-x, 600-y, 63);
+ drawstring(words4, 800-y, 600-x, 126);
+
+ drawstring(words3, 0, 0, 63);
+ drawstring(words4, 0, 70, 63);
+ drawstring(words1, 0, 140, 21);
+ drawstring(words2, 0, 168, 28);
+
+ glEnd();
+ }
+};
+
+int main(int argc, char* argv[]) {
+ gg mygame;
+ mygame.start();
+ return 0;
+}

No commit comments for this range

Something went wrong with that request. Please try again.