summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-05-11 19:30:31 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-05-11 19:30:31 +0200
commit63e3b825580c8fbf6b84d441c92ed39348e51c17 (patch)
tree1d315af990adf5160554ccf7e2fb615223b44220
parentd42ec5c0e89559abd276334b6c4804e1eaa5e9c7 (diff)
Working win32 port.
-rw-r--r--.gitignore2
-rw-r--r--Makefile.win326
-rw-r--r--gl.cpp116
-rw-r--r--gl.h55
-rw-r--r--main.cpp14
-rw-r--r--scene.cpp27
-rw-r--r--scene.h6
-rw-r--r--terrain.cpp13
-rw-r--r--terrain.h1
9 files changed, 132 insertions, 108 deletions
diff --git a/.gitignore b/.gitignore
index 30475e9..088042e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@
/dist
/Session.vim
/map
+*.dll
+*.exe
diff --git a/Makefile.win32 b/Makefile.win32
index 9981c58..7201493 100644
--- a/Makefile.win32
+++ b/Makefile.win32
@@ -2,11 +2,11 @@ CXX=g++
LD=g++
TARGET=foo.exe
#OBJECTS=$(shell ls *.cpp | sed 's/cpp/o/')
-OBJECTS=gl.o gui.o main.o terrain.o noiseutils/noiseutils.o scene.o shader.o tool.o vector.o video.o
+OBJECTS=gl.o gui.o main.o terrain.o noiseutils\noiseutils.o scene.o shader.o tool.o vector.o video.o
#-D_GNU_SOURCE=1 -D_REENTRANT
-CPPFLAGS=-IC:/mingw/include/SDL -IC:/mingw/include/CEGUI/ -g -mconsole #-mwin32
+CPPFLAGS=-IC:/MinGW/include/SDL -IC:/MinGW/include/CEGUI/ -IC:/MinGW/include/freetype2 -Wall -g -O3 -mconsole #-mwin32
LDFLAGS=-lCEGUIOpenGLRenderer -lCEGUIBase -lCEGUITGAImageCodec -lCEGUITinyXMLParser -lCEGUIFalagardWRBase -lCEGUISILLYImageCodec
-LDFLAGS+=-lSDL_image -lfreetype -lz -lpcre -lopengl32 -lglu32 -lwinmm -lmingw32 -lSDLmain -lSDL -ljpeg -lstdc++ -lboost_filesystem -lboost_system -lnoise
+LDFLAGS+=-lSDL_image -lftgl -lfreetype -lz -lpcre -lopengl32 -lglu32 -lwinmm -lmingw32 -lSDLmain -lSDL -ljpeg -lstdc++ -lboost_filesystem -lboost_system -lnoise
all: $(TARGET)
diff --git a/gl.cpp b/gl.cpp
index 54ab4c5..9cefa53 100644
--- a/gl.cpp
+++ b/gl.cpp
@@ -4,73 +4,75 @@
#ifdef WIN32
-void (*glGenBuffers)(GLsizei, GLuint*);
-void (*glDeleteBuffers)(GLsizei, GLuint*);
-void (*glBindBuffer)(GLenum, GLuint);
-void (*glBufferData)(GLenum, GLsizeiptr, const GLvoid*, GLenum);
-GLvoid* (*glMapBuffer)(GLenum, GLenum);
-GLboolean (*glUnmapBuffer)(GLenum);
+void (APIENTRY *glGenBuffers)(GLsizei, GLuint*);
+void (APIENTRY *glDeleteBuffers)(GLsizei, GLuint*);
+void (APIENTRY *glBindBuffer)(GLenum, GLuint);
+void (APIENTRY *glBufferData)(GLenum, GLsizeiptr, const GLvoid*, GLenum);
+GLvoid* (APIENTRY *glMapBuffer)(GLenum, GLenum);
+GLboolean (APIENTRY *glUnmapBuffer)(GLenum);
/* uniform */
-GLint (*glGetUniformLocation)(GLuint, const GLchar*);
-void (*glUniform1i)(GLint, GLint);
-void (*glUniform2f)(GLint, GLfloat, GLfloat);
-void (*glUniform3f)(GLint, GLfloat, GLfloat, GLfloat);
+GLint (APIENTRY *glGetUniformLocation)(GLuint, const GLchar*);
+void (APIENTRY *glUniform1i)(GLint, GLint);
+void (APIENTRY *glUniform2f)(GLint, GLfloat, GLfloat);
+void (APIENTRY *glUniform3f)(GLint, GLfloat, GLfloat, GLfloat);
+void (APIENTRY *glUniform1iv)(GLint, GLsizei, const GLint*);
/* texture */
-void (*glActiveTexture)(GLenum);
+void (APIENTRY *glActiveTexture)(GLenum);
/* program/shader */
-GLuint (*glCreateProgram)(void);
-void (*glLinkProgram)(GLuint);
-void (*glGetProgramiv)(GLuint, GLenum, GLint*);
-void (*glGetProgramInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
-void (*glUseProgram)(GLuint);
-void (*glDeleteProgram)(GLuint);
-
-GLuint (*glCreateShader)(GLenum);
-void (*glShaderSource)(GLuint, GLsizei, const GLchar**, const GLint*);
-void (*glCompileShader)(GLuint);
-void (*glGetShaderiv)(GLuint, GLenum, GLint*);
-void (*glGetShaderInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
-
-void (*glAttachShader)(GLuint, GLuint);
-void (*glDetachShader)(GLuint, GLuint);
-void (*glDeleteShader)(GLuint);
+GLuint (APIENTRY *glCreateProgram)(void);
+void (APIENTRY *glLinkProgram)(GLuint);
+void (APIENTRY *glGetProgramiv)(GLuint, GLenum, GLint*);
+void (APIENTRY *glGetProgramInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
+void (APIENTRY *glUseProgram)(GLuint);
+void (APIENTRY *glDeleteProgram)(GLuint);
+
+GLuint (APIENTRY *glCreateShader)(GLenum);
+void (APIENTRY *glShaderSource)(GLuint, GLsizei, const GLchar**, const GLint*);
+void (APIENTRY *glCompileShader)(GLuint);
+void (APIENTRY *glGetShaderiv)(GLuint, GLenum, GLint*);
+void (APIENTRY *glGetShaderInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
+
+void (APIENTRY *glAttachShader)(GLuint, GLuint);
+void (APIENTRY *glDetachShader)(GLuint, GLuint);
+void (APIENTRY *glDeleteShader)(GLuint);
//GL_DeleteBuffers glDeleteBuffers = NULL;
void win32_gl_init() {
- glGenBuffers = (void(*)(GLsizei, GLuint*))SDL_GL_GetProcAddress("glGenBuffers");
- glDeleteBuffers = (void(*)(GLsizei, GLuint*))SDL_GL_GetProcAddress("glDeleteBuffers");
- glBindBuffer = (void(*)(GLenum, GLuint))SDL_GL_GetProcAddress("glBindBuffer");
- glBufferData = (void(*)(GLenum, GLsizeiptr, const GLvoid*, GLenum))SDL_GL_GetProcAddress("glBufferData");
- glMapBuffer = (GLvoid*(*)(GLenum, GLenum))SDL_GL_GetProcAddress("glMapBuffer");
- glUnmapBuffer = (GLboolean(*)(GLenum))SDL_GL_GetProcAddress("glUnmapBuffer");
-
- glGetUniformLocation = (GLint(*)(GLuint, const GLchar*))SDL_GL_GetProcAddress("glGetUniformLocation");
- glUniform1i = (void(*)(GLint, GLint))SDL_GL_GetProcAddress("glUniform1i");
- glUniform2f = (void(*)(GLint, GLfloat, GLfloat))SDL_GL_GetProcAddress("glUniform2f");
- glUniform3f = (void(*)(GLint, GLfloat, GLfloat, GLfloat))SDL_GL_GetProcAddress("glUniform3f");
-
- glActiveTexture = (void(*)(GLenum))SDL_GL_GetProcAddress("glActiveTexture");
-
- glCreateProgram = (GLuint(*)(void))SDL_GL_GetProcAddress("glCreateProgram");
- glLinkProgram = (void(*)(GLuint))SDL_GL_GetProcAddress("glLinkProgram");
- glGetProgramiv = (void(*)(GLuint, GLenum, GLint*))SDL_GL_GetProcAddress("glGetProgramiv");
- glGetProgramInfoLog = (void(*)(GLuint, GLsizei, GLsizei*, GLchar*))SDL_GL_GetProcAddress("glGetProgramInfoLog");
- glUseProgram = (void(*)(GLuint))SDL_GL_GetProcAddress("glUseProgram");
- glDeleteProgram = (void(*)(GLuint))SDL_GL_GetProcAddress("glDeleteProgram");
-
- glCreateShader = (GLuint(*)(GLenum))SDL_GL_GetProcAddress("glCreateShader");
- glShaderSource = (void(*)(GLuint, GLsizei, const GLchar**, const GLint*))SDL_GL_GetProcAddress("glShaderSource");
- glCompileShader = (void(*)(GLuint))SDL_GL_GetProcAddress("glCompileShader");
- glGetShaderiv = (void(*)(GLuint, GLenum, GLint*))SDL_GL_GetProcAddress("glGetShaderiv");
- glGetShaderInfoLog = (void(*)(GLuint, GLsizei, GLsizei*, GLchar*))SDL_GL_GetProcAddress("glGetShaderInfoLog");
-
- glAttachShader = (void(*)(GLuint, GLuint))SDL_GL_GetProcAddress("glAttachShader");
- glDetachShader = (void(*)(GLuint, GLuint))SDL_GL_GetProcAddress("glDetachShader");
- glDeleteShader = (void(*)(GLuint))SDL_GL_GetProcAddress("glDeleteShader");
+ glGenBuffers = (void(APIENTRY*)(GLsizei, GLuint*))SDL_GL_GetProcAddress("glGenBuffers");
+ glDeleteBuffers = (void(APIENTRY*)(GLsizei, GLuint*))SDL_GL_GetProcAddress("glDeleteBuffers");
+ glBindBuffer = (void(APIENTRY*)(GLenum, GLuint))SDL_GL_GetProcAddress("glBindBuffer");
+ glBufferData = (void(APIENTRY*)(GLenum, GLsizeiptr, const GLvoid*, GLenum))SDL_GL_GetProcAddress("glBufferData");
+ glMapBuffer = (GLvoid*(APIENTRY*)(GLenum, GLenum))SDL_GL_GetProcAddress("glMapBuffer");
+ glUnmapBuffer = (GLboolean(APIENTRY*)(GLenum))SDL_GL_GetProcAddress("glUnmapBuffer");
+
+ glGetUniformLocation = (GLint(APIENTRY*)(GLuint, const GLchar*))SDL_GL_GetProcAddress("glGetUniformLocation");
+ glUniform1i = (void(APIENTRY*)(GLint, GLint))SDL_GL_GetProcAddress("glUniform1i");
+ glUniform2f = (void(APIENTRY*)(GLint, GLfloat, GLfloat))SDL_GL_GetProcAddress("glUniform2f");
+ glUniform3f = (void(APIENTRY*)(GLint, GLfloat, GLfloat, GLfloat))SDL_GL_GetProcAddress("glUniform3f");
+ glUniform1iv = (void(APIENTRY*)(GLint, GLsizei, const GLint*))SDL_GL_GetProcAddress("glUniform1iv");
+
+ glActiveTexture = (void(APIENTRY*)(GLenum))SDL_GL_GetProcAddress("glActiveTexture");
+
+ glCreateProgram = (GLuint(APIENTRY*)(void))SDL_GL_GetProcAddress("glCreateProgram");
+ glLinkProgram = (void(APIENTRY*)(GLuint))SDL_GL_GetProcAddress("glLinkProgram");
+ glGetProgramiv = (void(APIENTRY*)(GLuint, GLenum, GLint*))SDL_GL_GetProcAddress("glGetProgramiv");
+ glGetProgramInfoLog = (void(APIENTRY*)(GLuint, GLsizei, GLsizei*, GLchar*))SDL_GL_GetProcAddress("glGetProgramInfoLog");
+ glUseProgram = (void(APIENTRY*)(GLuint))SDL_GL_GetProcAddress("glUseProgram");
+ glDeleteProgram = (void(APIENTRY*)(GLuint))SDL_GL_GetProcAddress("glDeleteProgram");
+
+ glCreateShader = (GLuint(APIENTRY*)(GLenum))SDL_GL_GetProcAddress("glCreateShader");
+ glShaderSource = (void(APIENTRY*)(GLuint, GLsizei, const GLchar**, const GLint*))SDL_GL_GetProcAddress("glShaderSource");
+ glCompileShader = (void(APIENTRY*)(GLuint))SDL_GL_GetProcAddress("glCompileShader");
+ glGetShaderiv = (void(APIENTRY*)(GLuint, GLenum, GLint*))SDL_GL_GetProcAddress("glGetShaderiv");
+ glGetShaderInfoLog = (void(APIENTRY*)(GLuint, GLsizei, GLsizei*, GLchar*))SDL_GL_GetProcAddress("glGetShaderInfoLog");
+
+ glAttachShader = (void(APIENTRY*)(GLuint, GLuint))SDL_GL_GetProcAddress("glAttachShader");
+ glDetachShader = (void(APIENTRY*)(GLuint, GLuint))SDL_GL_GetProcAddress("glDetachShader");
+ glDeleteShader = (void(APIENTRY*)(GLuint))SDL_GL_GetProcAddress("glDeleteShader");
}
#endif
diff --git a/gl.h b/gl.h
index 1d3a151..1bbd9a5 100644
--- a/gl.h
+++ b/gl.h
@@ -9,39 +9,40 @@
#ifdef WIN32
/* buffer */
-extern void (*glGenBuffers)(GLsizei, GLuint*);
-extern void (*glDeleteBuffers)(GLsizei, GLuint*);
-extern void (*glBindBuffer)(GLenum, GLuint);
-extern void (*glBufferData)(GLenum, GLsizeiptr, const GLvoid*, GLenum);
-extern GLvoid* (*glMapBuffer)(GLenum, GLenum);
-extern GLboolean (*glUnmapBuffer)(GLenum);
+extern void (APIENTRY *glGenBuffers)(GLsizei, GLuint*);
+extern void (APIENTRY *glDeleteBuffers)(GLsizei, GLuint*);
+extern void (APIENTRY *glBindBuffer)(GLenum, GLuint);
+extern void (APIENTRY *glBufferData)(GLenum, GLsizeiptr, const GLvoid*, GLenum);
+extern GLvoid* (APIENTRY *glMapBuffer)(GLenum, GLenum);
+extern GLboolean (APIENTRY *glUnmapBuffer)(GLenum);
/* uniform */
-extern GLint (*glGetUniformLocation)(GLuint, const GLchar*);
-extern void (*glUniform1i)(GLint, GLint);
-extern void (*glUniform2f)(GLint, GLfloat, GLfloat);
-extern void (*glUniform3f)(GLint, GLfloat, GLfloat, GLfloat);
+extern GLint (APIENTRY *glGetUniformLocation)(GLuint, const GLchar*);
+extern void (APIENTRY *glUniform1i)(GLint, GLint);
+extern void (APIENTRY *glUniform2f)(GLint, GLfloat, GLfloat);
+extern void (APIENTRY *glUniform3f)(GLint, GLfloat, GLfloat, GLfloat);
+extern void (APIENTRY *glUniform1iv)(GLint, GLsizei, const GLint*);
/* texture */
-extern void (*glActiveTexture)(GLenum);
+extern void (APIENTRY *glActiveTexture)(GLenum);
/* program/shader */
-extern GLuint (*glCreateProgram)(void);
-extern void (*glLinkProgram)(GLuint);
-extern void (*glGetProgramiv)(GLuint, GLenum, GLint*);
-extern void (*glGetProgramInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
-extern void (*glUseProgram)(GLuint);
-extern void (*glDeleteProgram)(GLuint);
-
-extern GLuint (*glCreateShader)(GLenum);
-extern void (*glShaderSource)(GLuint, GLsizei, const GLchar**, const GLint*);
-extern void (*glCompileShader)(GLuint);
-extern void (*glGetShaderiv)(GLuint, GLenum, GLint*);
-extern void (*glGetShaderInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
-
-extern void (*glAttachShader)(GLuint, GLuint);
-extern void (*glDetachShader)(GLuint, GLuint);
-extern void (*glDeleteShader)(GLuint);
+extern GLuint (APIENTRY *glCreateProgram)(void);
+extern void (APIENTRY *glLinkProgram)(GLuint);
+extern void (APIENTRY *glGetProgramiv)(GLuint, GLenum, GLint*);
+extern void (APIENTRY *glGetProgramInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
+extern void (APIENTRY *glUseProgram)(GLuint);
+extern void (APIENTRY *glDeleteProgram)(GLuint);
+
+extern GLuint (APIENTRY *glCreateShader)(GLenum);
+extern void (APIENTRY *glShaderSource)(GLuint, GLsizei, const GLchar**, const GLint*);
+extern void (APIENTRY *glCompileShader)(GLuint);
+extern void (APIENTRY *glGetShaderiv)(GLuint, GLenum, GLint*);
+extern void (APIENTRY *glGetShaderInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
+
+extern void (APIENTRY *glAttachShader)(GLuint, GLuint);
+extern void (APIENTRY *glDetachShader)(GLuint, GLuint);
+extern void (APIENTRY *glDeleteShader)(GLuint);
void win32_gl_init();
#endif
diff --git a/main.cpp b/main.cpp
index 3dc9e27..4d050fc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,11 +5,22 @@
#include <SDL_image.h>
+bool init_sdl_image() {
+ int real_flags = IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
+ if(!(real_flags | IMG_INIT_PNG && real_flags | IMG_INIT_JPG)) {
+ std::cerr << "Missing PNG or JPEG libraries" << std::endl;
+ return false;
+ }
+ return true;
+}
+
int main(int argc, char **argv) {
+ if(!init_sdl_image())
+ return 1;
+
video::width = 1280;
video::height = 720;
video::init();
- IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
#ifdef WIN32
win32_gl_init();
@@ -22,7 +33,6 @@ int main(int argc, char **argv) {
SDL_WarpMouse(video::width/2, video::height/2);
scene->last_time = SDL_GetTicks();
scene->update();
- std::cout << "foo" << std::endl;
while(scene->running) {
scene->events();
scene->render();
diff --git a/scene.cpp b/scene.cpp
index cc7db04..e371f74 100644
--- a/scene.cpp
+++ b/scene.cpp
@@ -35,10 +35,9 @@ Scene::Scene() {
terrain_program.link();
terrain_program.use();
- GLint tex1loc = glGetUniformLocation(terrain_program.get_program(), "tex[1]");
- glUniform1i(tex1loc, 1);
- GLint tex2loc = glGetUniformLocation(terrain_program.get_program(), "tex[2]");
- glUniform1i(tex2loc, 2);
+ GLint tex = glGetUniformLocation(terrain_program.get_program(), "tex");
+ GLint texv[] = {0, 1, 2};
+ glUniform1iv(tex, 3, texv);
GLint markloc = glGetUniformLocation(terrain_program.get_program(), "marktex");
glUniform1i(markloc, 3);
glUseProgram(0);
@@ -53,8 +52,8 @@ Scene::Scene() {
terrain = new Terrain();
/* load font */
- //font = new FTTextureFont("fonts/VeraMono.ttf");
- //font->FaceSize(10);
+ font = new FTTextureFont("fonts/VeraMono.ttf");
+ font->FaceSize(10);
GUI::init();
}
@@ -64,7 +63,7 @@ Scene::~Scene() {
delete tool;
if(terrain)
delete terrain;
- //delete font;
+ delete font;
}
void Scene::lookat() {
@@ -395,14 +394,8 @@ void Scene::render() {
Terrain::Chunk *chunk = *it;
glPushMatrix();
glTranslatef(-pos.x, -pos.y, -pos.z);
- /*if(!chunk->nodes) {
- for(int i = 0; i < 4; i++)
- q.push(chunk->children[i]);
- continue;
- } else*/ if(chunk->vbo_object) {
- for(unsigned int i = 0; i < chunk->node_count; i++)
- chunk->nodes[i]->draw_grid();
- }
+ for(unsigned int i = 0; i < chunk->node_count; i++)
+ chunk->nodes[i]->draw_grid();
glPopMatrix();
}
}
@@ -448,7 +441,7 @@ void Scene::render() {
glPopMatrix();
video::ortho();
- /*float height = font->LineHeight();
+ float height = font->LineHeight();
glColor3f(1, 1, 1);
glTranslatef(0, video::height-height, 0);
font->Render((boost::format("chunks: %d gravity: %d steps: %d")
@@ -464,7 +457,7 @@ void Scene::render() {
if(tool) {
glTranslatef(0, -height, 0);
font->Render((boost::format("Tool: %s") % tool->get_name()).str().c_str());
- }*/
+ }
/*if(selected) {
glTranslatef(0, height, 0);
//font->Render((boost::format("(%s %s %s %s)") % selected->a->str() % selected->b->str() % selected->c->str() % selected->d->str()).str().c_str());
diff --git a/scene.h b/scene.h
index e700351..72bf506 100644
--- a/scene.h
+++ b/scene.h
@@ -8,7 +8,7 @@
#include "gui.h"
#include "tool.h"
-//#include <FTGL/ftgl.h>
+#include <FTGL/ftgl.h>
class Scene {
public:
@@ -16,7 +16,7 @@ class Scene {
Vector3 pos;
float yvel;
Terrain *terrain;
- //FTFont *font;
+ FTFont *font;
GUI *gui;
Tool *tool;
@@ -36,6 +36,8 @@ class Scene {
int sx, sy;
GLShaderProgram terrain_program;
+ //GLVertexShader terrain_vertex;
+ //GLFragmentShader terrain_fragment;
GLuint grass_texture, rock_texture, soil_texture, marker_texture;
diff --git a/terrain.cpp b/terrain.cpp
index 35aef58..1fd75db 100644
--- a/terrain.cpp
+++ b/terrain.cpp
@@ -73,6 +73,19 @@ void Terrain::Node::fill() {
vertex_array[11] = y;
}
+void Terrain::Node::draw() {
+ glBegin(GL_TRIANGLES);
+ for(int i = 0; i < 2; i++) {
+ glTexCoord2f(0, 0);
+ glVertex3f(vertex_array[0], vertex_array[1], vertex_array[2]);
+ glTexCoord2f(i, 1);
+ glVertex3f(vertex_array[i*3+3], vertex_array[i*3+4], vertex_array[i*3+5]);
+ glTexCoord2f(1, 1-i);
+ glVertex3f(vertex_array[i*3+6], vertex_array[i*3+7], vertex_array[i*3+8]);
+ }
+ glEnd();
+}
+
void Terrain::Node::draw_grid() {
glNormal3f(0, 1, 0);
glBegin(GL_LINE_LOOP);
diff --git a/terrain.h b/terrain.h
index 736b719..84abe26 100644
--- a/terrain.h
+++ b/terrain.h
@@ -23,6 +23,7 @@ class Terrain {
float distance(float px, float pz);
void fill();
+ void draw();
void draw_grid();
void draw_normal();
float get_height(float px, float py);