Skip to content

Commit

Permalink
Adding experimental support for the GP2X Wiz handheld. Many things ar…
Browse files Browse the repository at this point in the history
…e still missing.

git-svn-id: file:///private-backup/var/svn/jngl@93 8b392cba-0c28-4fbc-ad53-5d9c93102ef3
  • Loading branch information
jhasse committed Aug 7, 2009
1 parent 32c4cb2 commit 371bd98
Show file tree
Hide file tree
Showing 14 changed files with 1,463 additions and 30 deletions.
25 changes: 18 additions & 7 deletions SConstruct
Expand Up @@ -23,19 +23,21 @@ debug = ARGUMENTS.get('debug', 0)
profile = ARGUMENTS.get('profile', 0)
autopackage = ARGUMENTS.get('autopackage', 0)
installer = ARGUMENTS.get('installer', 0)
opengles = ARGUMENTS.get('opengles', 0)
python = int(ARGUMENTS.get('python', 0))
m32 = ARGUMENTS.get('m32', 0)
wiz = ARGUMENTS.get('wiz', 0)
if int(debug):
env.Append(CCFLAGS = '-g -Wall')
else:
env.Append(CCFLAGS = '-O2 -DNDEBUG')
if int(profile):
env.Append(CCFLAGS = '-pg', _LIBFLAGS = ' -pg')
if int(opengles):
env.Append(CCFLAGS = '-DOPENGLES')
if int(m32):
env.Append(CCFLAGS = '-m32', LINKFLAGS = ' -m32')
if int(wiz):
env['CXX'] = "/toolchain/bin/arm-openwiz-linux-gnu-g++"
env['CC'] = "/toolchain/bin/arm-openwiz-linux-gnu-gcc"
env.Append(CPPPATH=["/toolchain/include", "wiz"], LIBPATH=["/toolchain/lib", "wiz"])

source_files = Split("""
finally.cpp
Expand Down Expand Up @@ -69,10 +71,19 @@ if env['PLATFORM'] == 'win32': # Windows
LINKFLAGS=linkflags)

if env['PLATFORM'] == 'posix': # Linux
env.ParseConfig('pkg-config --cflags --libs freetype2 fontconfig glib-2.0')
lib = env.Library(target="jngl", source=source_files + Glob('linux/*.cpp'))
if int(wiz):
env.Append(CCFLAGS = '-DWIZ -DOPENGLES')
source_files += Glob('wiz/*.cpp')
else:
source_files += Glob('linux/*.cpp')
env.ParseConfig('pkg-config --cflags --libs fontconfig glib-2.0')
env.ParseConfig('pkg-config --cflags --libs freetype2')
lib = env.Library(target="jngl", source=source_files)
env.Append(LIBPATH=".", CPPPATH='.')
env.ParseConfig("pkg-config --cflags --libs jngl.pc")
if wiz:
env.Append(LIBS=Split("jpeg jngl nanoGL wizGLES opengles_lite z png dl"))
else:
env.ParseConfig("pkg-config --cflags --libs jngl.pc")
env.Program("test.cpp")

if int(autopackage):
Expand All @@ -92,4 +103,4 @@ if int(installer):
t = Command('jngl Library ' + version + '.exe', lib, '"' + os.path.expandvars("%programfiles%") + '\NSIS\makensis.exe " ' + nsiFile)
if python:
Depends(t, 'python/jngl.dll')
Clean(t, 'installer/JNGL ' + version + ' (' + name + ').exe')
Clean(t, 'installer/JNGL ' + version + ' (' + name + ').exe')
4 changes: 2 additions & 2 deletions draw.hpp
Expand Up @@ -34,7 +34,7 @@ namespace draw
opengl::Translate(xposition, yposition);
T rect[] = { 0, 0, width, 0, width, height, 0, height };
glVertexPointer(2, opengl::Type<T>::constant, 0, rect);
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glPopMatrix();
}

Expand Down Expand Up @@ -62,7 +62,7 @@ namespace draw
++count;
}
glVertexPointer(2, opengl::Type<T>::constant, 0, &vertexes[0]);
glDrawArrays(GL_POLYGON, 0, count);
glDrawArrays(GL_TRIANGLE_FAN, 0, count);
glPopMatrix();
}

Expand Down
2 changes: 1 addition & 1 deletion freetype.cpp
Expand Up @@ -123,7 +123,7 @@ namespace jngl
glBindTexture(GL_TEXTURE_2D, texture_);
glVertexPointer(2, GL_INT, 0, &vertexes_[0]);
glTexCoordPointer(2, GL_FLOAT, 0, &texCoords_[0]);
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
Expand Down
12 changes: 9 additions & 3 deletions main.cpp
Expand Up @@ -247,22 +247,26 @@ namespace jngl

void Rotate(const double degree)
{
#ifdef GL_DOUBLE
glRotated(degree, 0, 0, 1);
#else
glRotatef(degree, 0, 0, 1);
#endif
}

void Translate(const double x, const double y)
{
glTranslated(x, y, 0);
opengl::Translate(x, y);
}

void Scale(const double factor)
{
glScaled(factor, factor, 0);
opengl::Scale(factor, factor);
}

void Scale(const double xfactor, const double yfactor)
{
glScaled(xfactor, yfactor, 0);
opengl::Scale(xfactor, yfactor);
}

void PushMatrix()
Expand Down Expand Up @@ -327,6 +331,7 @@ namespace jngl

void SetAntiAliasing(bool enabled)
{
#ifdef GL_MULTISAMPLE_ARB
if(!pWindow->IsMultisampleSupported())
{
antiAliasingEnabled = false;
Expand All @@ -341,6 +346,7 @@ namespace jngl
glDisable(GL_MULTISAMPLE_ARB);
}
antiAliasingEnabled = enabled;
#endif
}

bool GetAntiAliasing()
Expand Down
22 changes: 19 additions & 3 deletions opengl.hpp
Expand Up @@ -19,9 +19,10 @@ along with JNGL. If not, see <http://www.gnu.org/licenses/>.

#pragma once

#ifdef OPENGLES
#include <GLES/egl.h>
#include <GLES/gl.h>
#ifdef WIZ
#include <GL/nanogl.h>
#include <GL/wizGLES.h>
#include <GL/egl.h>
#else
#ifndef linux
#include <windows.h>
Expand All @@ -31,15 +32,24 @@ along with JNGL. If not, see <http://www.gnu.org/licenses/>.

#include <boost/function.hpp>

#ifndef GL_BGR
#define GL_BGR 0x80e0
#endif

namespace opengl
{
inline void Translate(float x, float y) { glTranslatef(x, y, 0); }
inline void Scale(float x, float y) { glScalef(x, y, 0); }
#ifdef GL_DOUBLE
template<class T, class U>
inline void Translate(T x, U y) { glTranslated(static_cast<double>(x), static_cast<double>(y), 0); }
template<class T, class U>
inline void Scale(T x, U y) { glScaled(static_cast<double>(x), static_cast<double>(y), 0); }
#else
template<class T, class U>
inline void Translate(T x, U y) { Translate(static_cast<float>(x), static_cast<float>(y)); }
template<class T, class U>
inline void Scale(T x, U y) { Scale(static_cast<float>(x), static_cast<float>(y)); }
#endif
#ifdef GL_FIXED
inline void Translate(int x, int y) { glTranslatex(x, y, 0); }
Expand Down Expand Up @@ -73,6 +83,12 @@ namespace opengl
#endif
};

#ifdef GL_DOUBLE
typedef GLdouble CoordType;
#else
typedef GLfloat CoordType;
#endif

// This function gets the first power of 2 >= the int that we pass it.
int NextPowerOf2(int);
}
14 changes: 8 additions & 6 deletions texture.cpp
Expand Up @@ -43,7 +43,9 @@ along with JNGL. If not, see <http://www.gnu.org/licenses/>.
#define XMD_H
#define HAVE_BOOLEAN
#endif
extern "C" {
#include <jpeglib.h>
}

namespace jngl
{
Expand Down Expand Up @@ -109,8 +111,8 @@ namespace jngl

glBindTexture(GL_TEXTURE_2D, texture_);
glVertexPointer(2, GL_INT, 0, &vertexes_[0]);
glTexCoordPointer(2, GL_DOUBLE, 0, &texCoords_[0]);
glDrawArrays(GL_QUADS, 0, 4);
glTexCoordPointer(2, opengl::Type<double>::constant, 0, &texCoords_[0]);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
Expand Down Expand Up @@ -149,8 +151,8 @@ namespace jngl
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, width, 1, format, GL_UNSIGNED_BYTE, &empty[0]);
}

const GLdouble x = static_cast<GLdouble>(imgWidth) / static_cast<GLdouble>(width);
const GLdouble y = static_cast<GLdouble>(imgHeight) / static_cast<GLdouble>(height);
const opengl::CoordType x = static_cast<opengl::CoordType>(imgWidth) / static_cast<opengl::CoordType>(width);
const opengl::CoordType y = static_cast<opengl::CoordType>(imgHeight) / static_cast<opengl::CoordType>(height);
GLfloat texCoords[] = { 0, 0, 0, y, x, y, x, 0 };
texCoords_.assign(&texCoords[0], &texCoords[8]);

Expand Down Expand Up @@ -352,12 +354,12 @@ namespace jngl
{
glPushMatrix();
opengl::Translate(xposition, yposition);
glScaled(xfactor, yfactor, 0);
opengl::Scale(xfactor, yfactor);
DrawTexture();
glPopMatrix();
}
private:
std::vector<GLdouble> texCoords_;
std::vector<opengl::CoordType> texCoords_;
std::vector<GLint> vertexes_;
GLuint texture_;
int width_, height_;
Expand Down
31 changes: 23 additions & 8 deletions window.hpp
Expand Up @@ -31,10 +31,14 @@ along with JNGL. If not, see <http://www.gnu.org/licenses/>.
#include <map>

#ifdef linux
#include <GL/glx.h>
#include <GL/glu.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/keysym.h>
#ifdef WIZ

#else
#include <GL/glx.h>
#include <GL/glu.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/keysym.h>
#endif
#else
#include <windows.h>
#endif
Expand Down Expand Up @@ -74,12 +78,16 @@ namespace jngl
void SetFont(const std::string&);
void SetFontByName(const std::string&);
bool IsMultisampleSupported() const;
#ifdef linux
#ifdef WIZ

#else
#ifdef linux
boost::shared_ptr<Display> pDisplay_;
static void ReleaseXData(void*);
#else
#else
static void ReleaseDC(HWND, HDC);
static void ReleaseRC(HGLRC);
#endif
#endif
private:
int GetKeyCode(jngl::key::KeyType key);
Expand All @@ -96,12 +104,18 @@ namespace jngl

// <fontSize, <fontName, Font> >
boost::ptr_map<int, boost::ptr_map<std::string, Font> > fonts_;
#ifdef linux
#ifdef WIZ
NativeWindowType nativeWindow_;
EGLDisplay display_;
EGLContext context_;
EGLSurface surface_;
#else
#ifdef linux
::Window window_;
GLXContext context_;
int screen_;
XF86VidModeModeInfo oldMode_;
#else
#else
boost::shared_ptr<boost::remove_pointer<HGLRC>::type> pRenderingContext_;
boost::shared_ptr<boost::remove_pointer<HWND>::type> pWindowHandle_;
boost::shared_ptr<boost::remove_pointer<HDC>::type> pDeviceContext_;
Expand All @@ -110,6 +124,7 @@ namespace jngl
bool InitMultisample(HINSTANCE, PIXELFORMATDESCRIPTOR);
void Init(const std::string& title, bool multisample);
void DistinguishLeftRight();
#endif
#endif
};
}

0 comments on commit 371bd98

Please sign in to comment.