From ae0130e815c353c7fc045d7bb510e919f0f87231 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 29 Apr 2011 22:10:14 +0200 Subject: win32 port wip --- gl.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gl.h | 42 ++++++++++++++++++++++++++++++++++++ gui.h | 2 ++ main.cpp | 7 ++++++ scene.cpp | 10 ++++----- scene.h | 4 ++-- 6 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 gl.cpp diff --git a/gl.cpp b/gl.cpp new file mode 100644 index 0000000..8152f05 --- /dev/null +++ b/gl.cpp @@ -0,0 +1,74 @@ +#include "gl.h" + +#include + +#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); + +/* uniform */ +GLint (*glGetUniformLocation)(GLuint, const GLchar*); +void (*glUniform1i)(GLint, GLint); +void (*glUniform3f)(GLint, GLfloat, GLfloat, GLfloat); + +/* texture */ +void (*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); + +//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"); + 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"); +} + +#endif diff --git a/gl.h b/gl.h index bb28c20..575a0ec 100644 --- a/gl.h +++ b/gl.h @@ -1,7 +1,49 @@ #ifndef GL_H #define GL_H +#ifndef WIN32 #define GL_GLEXT_PROTOTYPES +#endif + #include +#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); + +/* uniform */ +extern GLint (*glGetUniformLocation)(GLuint, const GLchar*); +extern void (*glUniform1i)(GLint, GLint); +extern void (*glUniform3f)(GLint, GLfloat, GLfloat, GLfloat); + +/* texture */ +extern void (*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); + +void win32_gl_init(); +#endif + + #endif diff --git a/gui.h b/gui.h index 30bf6dd..7e61197 100644 --- a/gui.h +++ b/gui.h @@ -1,6 +1,8 @@ #ifndef GUI_H #define GUI_H +#define CEGUI_STATIC + #include class GUI { diff --git a/main.cpp b/main.cpp index d6ad962..643b3b4 100644 --- a/main.cpp +++ b/main.cpp @@ -8,6 +8,13 @@ int main(int argc, char **argv) { video::height = 720; video::init(); +#ifdef WIN32 + win32_gl_init(); +#ifdef CEGUI_STATIC +#warning "cegui static" +#endif +#endif + Scene scene; SDL_ShowCursor(SDL_DISABLE); diff --git a/scene.cpp b/scene.cpp index 6cb6cc7..7a2a740 100644 --- a/scene.cpp +++ b/scene.cpp @@ -61,8 +61,8 @@ Scene::Scene() { qt = new Quadtree(w, h, heightmap); /* load font */ - font = new FTTextureFont("fonts/VeraMono.ttf"); - font->FaceSize(10); + //font = new FTTextureFont("fonts/VeraMono.ttf"); + //font->FaceSize(10); GUI::init(); } @@ -72,7 +72,7 @@ Scene::~Scene() { delete tool; if(qt) delete qt; - delete font; + //delete font; } void Scene::lookat() { @@ -408,7 +408,7 @@ void Scene::render() { } video::ortho(); - float height = font->LineHeight(); + /*float height = font->LineHeight(); glColor3f(1, 1, 1); glTranslatef(0, video::height-height, 0); font->Render((boost::format("%dx%d chunks: %d gravity: %d steps: %d") @@ -424,7 +424,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 59f0c79..3131474 100644 --- a/scene.h +++ b/scene.h @@ -8,7 +8,7 @@ #include "gui.h" #include "tool.h" -#include +//#include class Scene { public: @@ -16,7 +16,7 @@ class Scene { Vector3 pos; float yvel; Quadtree *qt; - FTFont *font; + //FTFont *font; GUI *gui; Tool *tool; -- cgit v1.2.3 From 965956ff2411bef4a26e66154fe56e6dc5d482ed Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 1 May 2011 21:24:44 +0200 Subject: Added makefile, debugging stuff. --- Makefile.win32 | 15 +++++++++++++++ main.cpp | 20 +++++++++++--------- quadtree.cpp | 9 ++++++++- scene.cpp | 10 ++++++++++ 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 Makefile.win32 diff --git a/Makefile.win32 b/Makefile.win32 new file mode 100644 index 0000000..710c370 --- /dev/null +++ b/Makefile.win32 @@ -0,0 +1,15 @@ +CXX=i486-mingw32-g++ +LD=i486-mingw32-g++ +TARGET=foo.exe +OBJECTS=$(shell ls *.cpp | sed 's/cpp/o/') +#-D_GNU_SOURCE=1 -D_REENTRANT +CPPFLAGS=-I/usr/i486-mingw32/include/SDL -I/usr/i486-mingw32/include/CEGUI/ -g -mconsole -mwin32 +LDFLAGS=-lCEGUIOpenGLRenderer -lCEGUIBase -lCEGUITGAImageCodec -lCEGUITinyXMLParser -lCEGUIFalagardWRBase -lSDL_image -lfreetype -lz -lpcre -lopengl32 -lglu32 -lwinmm -lmingw32 -lSDLmain -lSDL -ljpeg + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + $(LD) -o $@ $^ $(LDFLAGS) + +clean: + rm -f $(OBJECTS) $(TARGET) diff --git a/main.cpp b/main.cpp index 643b3b4..3dc9e27 100644 --- a/main.cpp +++ b/main.cpp @@ -3,32 +3,34 @@ #include "gl.h" +#include + int main(int argc, char **argv) { video::width = 1280; video::height = 720; video::init(); + IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG); #ifdef WIN32 win32_gl_init(); -#ifdef CEGUI_STATIC -#warning "cegui static" -#endif #endif - Scene scene; + Scene *scene = new Scene(); SDL_ShowCursor(SDL_DISABLE); SDL_WarpMouse(video::width/2, video::height/2); - scene.last_time = SDL_GetTicks(); - scene.update(); - while(scene.running) { - scene.events(); - scene.render(); + scene->last_time = SDL_GetTicks(); + scene->update(); + std::cout << "foo" << std::endl; + while(scene->running) { + scene->events(); + scene->render(); SDL_Delay(1); } + delete scene; video::free(); return 0; diff --git a/quadtree.cpp b/quadtree.cpp index 65c60ae..3b329ac 100644 --- a/quadtree.cpp +++ b/quadtree.cpp @@ -343,11 +343,15 @@ Quadtree::QuadNode* Quadtree::QuadChunk::find(float x, float y) { /* Quadtree */ Quadtree::Quadtree(int width, int height, float *heightmap) { + std::cout << "width: " << width << " height: " << height << std::endl; + std::cout << "heightmap: " << heightmap << std::endl; + this->width = width; this->height = height; heights = heightmap; - root = new QuadChunk(this, 0, 0, width-1, height-1); + this->root = new QuadChunk(this, 0, 0, width-1, height-1); + std::cout << "root: " << root << std::endl; normals = new Vector3[width*height]; for(int x = 0; x < width; x++) { @@ -439,15 +443,18 @@ Vector3 Quadtree::calc_normal(int x, int y) { void Quadtree::update(float x, float z) { std::queue q; + std::cout << "root: " << root << std::endl; q.push(root); while(!q.empty()) { QuadChunk *chunk = q.front(); q.pop(); + std::cout << "chunk: " << chunk << std::endl; if(!chunk->nodes) { for(int i = 0; i < 4; i++) q.push(chunk->children[i]); continue; } + std::cout << "foo" << std::endl; float d = chunk->distance(x, z); if(d < 100 && !chunk->vbo_object) { diff --git a/scene.cpp b/scene.cpp index 7a2a740..bcec2bf 100644 --- a/scene.cpp +++ b/scene.cpp @@ -6,6 +6,7 @@ #include "gl.h" +#include #include #include @@ -48,17 +49,25 @@ Scene::Scene() { /* load heightmap */ SDL_Surface *hm = IMG_Load("heightmap.png"); + std::cout << (boost::format("size: %dx%d") % hm->w % hm->h).str() << std::endl; + std::cout << "size: " << hm->w << "x" << hm->h << std::endl; + printf("size: %dx%d\n", hm->w, hm->h); float *heightmap = new float[hm->w * hm->h]; for(int x = 0; x < hm->w; x++) { for(int y = 0; y < hm->h; y++) { Uint8 *p = (Uint8*)hm->pixels + y * hm->pitch + x * hm->format->BytesPerPixel; + if(y*hm->w + x >= hm->w * hm->h) + std::cout << "foo" << std::endl; heightmap[y*hm->w + x] = ((float)(*p) / 256) * 20; } } int w = hm->w; int h = hm->h; SDL_FreeSurface(hm); + float *hmap = heightmap; + std::cout << "heightmap: " << heightmap << std::endl; qt = new Quadtree(w, h, heightmap); + std::cout << "qt: " << qt << std::endl; /* load font */ //font = new FTTextureFont("fonts/VeraMono.ttf"); @@ -140,6 +149,7 @@ bool Scene::select(int x, int y, float& px, float& py, float& pz) { } void Scene::update() { + std::cout << "qt: " << qt << std::endl; qt->update(pos.x, pos.z); } -- cgit v1.2.3 From fa1216b691dc5be3429858dcff845239b1aec417 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 10 May 2011 16:04:26 +0200 Subject: Updated makefile. --- Makefile.win32 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile.win32 b/Makefile.win32 index 710c370..f63789a 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -1,10 +1,12 @@ -CXX=i486-mingw32-g++ -LD=i486-mingw32-g++ +CXX=g++ +LD=g++ TARGET=foo.exe -OBJECTS=$(shell ls *.cpp | sed 's/cpp/o/') +#OBJECTS=$(shell ls *.cpp | sed 's/cpp/o/') +OBJECTS=gl.o gui.o main.o quadtree.o scene.o shader.o tool.o vector.o video.o #-D_GNU_SOURCE=1 -D_REENTRANT -CPPFLAGS=-I/usr/i486-mingw32/include/SDL -I/usr/i486-mingw32/include/CEGUI/ -g -mconsole -mwin32 -LDFLAGS=-lCEGUIOpenGLRenderer -lCEGUIBase -lCEGUITGAImageCodec -lCEGUITinyXMLParser -lCEGUIFalagardWRBase -lSDL_image -lfreetype -lz -lpcre -lopengl32 -lglu32 -lwinmm -lmingw32 -lSDLmain -lSDL -ljpeg +CPPFLAGS=-IC:/mingw/include/SDL -IC:/mingw/include/CEGUI/ -g -mconsole #-mwin32 +LDFLAGS=-lCEGUIOpenGLRenderer -lCEGUIBase -lCEGUITGAImageCodec -lCEGUITinyXMLParser -lCEGUIFalagardWRBase +LDFLAGS+=-lSDL_image -lfreetype -lz -lpcre -lopengl32 -lglu32 -lwinmm -lmingw32 -lSDLmain -lSDL -ljpeg -lstdc++ all: $(TARGET) @@ -12,4 +14,4 @@ $(TARGET): $(OBJECTS) $(LD) -o $@ $^ $(LDFLAGS) clean: - rm -f $(OBJECTS) $(TARGET) + del $(OBJECTS) $(TARGET) -- cgit v1.2.3 From 63e3b825580c8fbf6b84d441c92ed39348e51c17 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 11 May 2011 19:30:31 +0200 Subject: Working win32 port. --- .gitignore | 2 + Makefile.win32 | 6 +-- gl.cpp | 116 +++++++++++++++++++++++++++++---------------------------- gl.h | 55 +++++++++++++-------------- main.cpp | 14 ++++++- scene.cpp | 27 +++++--------- scene.h | 6 ++- terrain.cpp | 13 +++++++ terrain.h | 1 + 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 +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 +#include 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); -- cgit v1.2.3 From bd843834dd6655d96b64d1ab72ab7b2983946199 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 11 May 2011 20:11:43 +0200 Subject: Fixed cross-compiling. --- Makefile.win32 | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/Makefile.win32 b/Makefile.win32 index 7201493..4b64070 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -1,12 +1,33 @@ -CXX=g++ -LD=g++ +ifeq ($(shell uname), Linux) + CXX=i486-mingw32-g++ + LD=i486-mingw32-g++ + ROOT=/usr/i486-mingw32 +else + CXX=g++ + LD=g++ + ROOT=C:/MinGW +endif + 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 scene.o shader.o tool.o vector.o video.o + +ifeq ($(shell uname), Linux) + OBJECTS+=noiseutils/noiseutils.o +else + OBJECTS+=noiseutils\noiseutils.o +endif + #-D_GNU_SOURCE=1 -D_REENTRANT -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 -lftgl -lfreetype -lz -lpcre -lopengl32 -lglu32 -lwinmm -lmingw32 -lSDLmain -lSDL -ljpeg -lstdc++ -lboost_filesystem -lboost_system -lnoise +CPPFLAGS=-I$(ROOT)/include/SDL -I$(ROOT)/include/CEGUI/ -I$(ROOT)/include/freetype2 -Wall -g -mconsole #-mwin32 +LDFLAGS=-L$(ROOT)/lib -lCEGUIOpenGLRenderer -lCEGUIBase -lCEGUITGAImageCodec -lCEGUITinyXMLParser -lCEGUIFalagardWRBase -lCEGUISILLYImageCodec +LDFLAGS+=-lSDL_image -lftgl -lfreetype -lz -lpcre -lopengl32 -lglu32 -lwinmm -lmingw32 -lSDLmain -lSDL -ljpeg -lstdc++ -lnoise + +ifeq ($(shell uname), Linux) + LDFLAGS+=-lboost_filesystem-mt-s -lboost_system-mt-s +else + LDFLAGS+=-lboost_filesystem -lboost_system +endif all: $(TARGET) -- cgit v1.2.3