summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar chirs241097@gmail.com <chirs241097@gmail.com@c17bf020-1265-9734-9302-a83f62007ddb> 2014-03-20 13:30:51 +0000
committerGravatar chirs241097@gmail.com <chirs241097@gmail.com@c17bf020-1265-9734-9302-a83f62007ddb> 2014-03-20 13:30:51 +0000
commitb0b2b1d18bc4d0e01e607d8c5316b2d4d41f2538 (patch)
tree629a66cda689cba7bc7ff29a4f871a8e86659f1b
parent57445c9930d6bf8f534d3fb6d9571dab5cfa1fcc (diff)
downloadbullet-lab-remix-b0b2b1d18bc4d0e01e607d8c5316b2d4d41f2538.tar.xz
Merge hge freetype support from a local testing branch. Small bug fixes.
-rwxr-xr-xCHANGELOG.TXT9
-rw-r--r--global.h1
-rw-r--r--hgeft.cpp93
-rw-r--r--hgeft.h74
-rw-r--r--levels.h2
-rw-r--r--main.cpp18
6 files changed, 189 insertions, 8 deletions
diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT
index 75ab8cb..a796421 100755
--- a/CHANGELOG.TXT
+++ b/CHANGELOG.TXT
@@ -1,8 +1,9 @@
===================================================================
Next version:
-??????
-New levels...
-Add missing tips.
+0.8.1-1_PR (b77)
+New level.
+Random segmentation fault in "Hyper-threading".
+Random crashes in Windows.
Pre-Released versions:
0.8.1-0_PR (b76)
@@ -14,7 +15,9 @@ New level "Double reflective".
Make point bullet additive blending.
Allow bullets to pause before being accelerated.
Add command line argument support. Use "--help" for usage.
+Add freetype support to hge. It's still pretty buggy.
Modify player speed settings.
+Beewx still messes up memory... fixed now.
0.8.0-1_PR (b75)
New level Supernova.
diff --git a/global.h b/global.h
index 9c8c1ba..8c17718 100644
--- a/global.h
+++ b/global.h
@@ -252,6 +252,7 @@ double clockrot,deltarot,deltadelta;
double whirot,dwhirot;
hgeSprite *playerspr;
DWORD DBGColor;
+hgeTTFont rbPanelFont;
int frameleft,infofade;
int level,part,clrtime,clrbns;
int coll,semicoll,mode,dsmc,restarts;
diff --git a/hgeft.cpp b/hgeft.cpp
new file mode 100644
index 0000000..5beca1e
--- /dev/null
+++ b/hgeft.cpp
@@ -0,0 +1,93 @@
+#include "hgeft.h"
+void hgeTTChar::Free(){if(quad.tex)hge->Texture_Free(quad.tex),quad.tex=0;}
+bool hgeTTChar::SetChar(wchar_t ch,FT_Face ttfface)
+{
+ FT_GlyphSlot slot=ttfface->glyph;
+ FT_UInt glyph_index=FT_Get_Char_Index(ttfface,ch);
+ FT_Error err=FT_Load_Glyph(ttfface,glyph_index,FT_LOAD_DEFAULT);
+ if(err)return false;
+ err=FT_Render_Glyph(ttfface->glyph,FT_RENDER_MODE_NORMAL);
+ if(err)return false;
+ _w=slot->advance.x>>6;_h=slot->bitmap.rows;//we are one line only.
+ rw=slot->bitmap.width;rh=slot->bitmap.rows;
+ quad.tex=hge->Texture_Create(
+ slot->bitmap.width?slot->bitmap.width:1,
+ slot->bitmap.rows?slot->bitmap.rows:1);
+ DWORD* tx=hge->Texture_Lock(quad.tex,false,0,0,
+ slot->bitmap.width?slot->bitmap.width:1,
+ slot->bitmap.rows?slot->bitmap.rows:1);
+ memset(tx,0,sizeof(DWORD)*(slot->bitmap.width?slot->bitmap.width:1)*(slot->bitmap.rows?slot->bitmap.rows:1));
+ int ptr=0;
+ for(int i=0;i<slot->bitmap.rows;++i)
+ for(int j=0;j<slot->bitmap.width;++j)
+ {
+#ifdef WIN32
+ tx[i*slot->bitmap.width+j]=ARGB(slot->bitmap.buffer[ptr],255,255,255);
+#else
+ tx[(slot->bitmap.rows-i-1)*slot->bitmap.width+j]=ARGB(slot->bitmap.buffer[ptr],255,255,255);
+ //In OpenGL, textures are locked upside down...
+#endif
+ ptr++;
+ }
+ hge->Texture_Unlock(quad.tex);
+ quad.v[0].tx=0;quad.v[0].ty=0;quad.v[1].tx=1;quad.v[1].ty=0;
+ quad.v[2].tx=1;quad.v[2].ty=1;quad.v[3].tx=0;quad.v[3].ty=1;
+ return true;
+}
+void hgeTTChar::Render(double x,double y,DWORD col)
+{
+ for(int i=0;i<4;++i)quad.v[i].col=col;
+ quad.v[0].x=x;quad.v[0].y=y-rh;
+ quad.v[1].x=x+rw;quad.v[1].y=y-rh;
+ quad.v[2].x=x+rw;quad.v[2].y=y;
+ quad.v[3].x=x;quad.v[3].y=y;
+ hge->Gfx_RenderQuad(&quad);
+}
+bool hgeTTFont::Init(const char *ttf,int size)
+{
+ FT_Error err=FT_Init_FreeType(&libft);
+ if(err)return false;
+ err=FT_New_Face(libft,ttf,0,&ttfface);
+ if(err)return false;
+ err=FT_Set_Char_Size(ttfface,0,size*64,96,96);
+ return true;
+}
+void hgeTTFont::UpdateString(const wchar_t *format, ...)
+{
+ for(int i=0;buf[i]!='\0';++i)chars[i].Free();
+ memset(buf,0,sizeof(buf));memset(chars,0,sizeof(chars));
+ va_list vl;
+ va_start(vl,format);
+ vswprintf(buf,1024,format,vl);
+ va_end(vl);
+ buf[1024]='\0';
+ w=h=0;
+ for(int i=0;buf[i]!='\0';++i)
+ {
+ chars[i].SetChar(buf[i],ttfface);
+ w+=chars[i].w();
+ if(chars[i].h()>h)h=chars[i].h();
+ }
+}
+void hgeTTFont::Render(double x,double y,DWORD color,int align)
+{
+ int cur;
+ if(align==0)
+ {
+ cur=x;
+ for(int i=0;buf[i]!='\0';++i)
+ {
+ chars[i].Render(cur,y,color);
+ cur+=chars[i].w();
+ }
+ }
+ if(align==1)
+ {
+ cur=x;
+ for(int i=wcslen(buf)-1;i>=0;--i)
+ {
+ chars[i].Render(cur,y,color);
+ cur-=chars[i].w();
+ }
+ }
+}
diff --git a/hgeft.h b/hgeft.h
new file mode 100644
index 0000000..e17ba42
--- /dev/null
+++ b/hgeft.h
@@ -0,0 +1,74 @@
+/*
+ * Freetype2 extention for hge
+ * by Chris Xiong
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of the nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Note: freetype 2.5.2 or newer is required.
+ * This library is somehow buggy, known bugs:
+ * * blinking charcter...
+ * * segmentation fault(fixed now)
+ * * Slow... but it's hard to improve...
+ * * Only support a single line...
+ *
+ */
+#ifndef HGEEFT_H
+#define HGEEFT_H
+#include <cstring>
+#include <cwchar>
+#include <hge.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+extern HGE* hge;
+class hgeTTChar
+{
+private:
+ hgeQuad quad;
+ int rw,rh,_w,_h;
+public:
+ double w(){return _w;}
+ double h(){return _h;}
+ void Free();
+ bool SetChar(wchar_t ch,FT_Face ttfface);
+ void Render(double x,double y,DWORD col);
+};
+class hgeTTFont
+{
+protected:
+ FT_Library libft;
+ FT_Face ttfface;
+ wchar_t buf[1025];
+ hgeTTChar chars[1024];
+ double w,h;
+public:
+ bool Init(const char *ttf,int size);
+ double GetWidth(){return w;}
+ double GetHeight(){return h;}
+ void UpdateString(const wchar_t *format, ...);
+ void Render(double x,double y,DWORD color,int align);
+};
+#endif
diff --git a/levels.h b/levels.h
index f685732..db758ba 100644
--- a/levels.h
+++ b/levels.h
@@ -1786,7 +1786,7 @@ void Level6Part17()
}
}
//begin hexagon
-Bullet bheader[100],*beewx[800];
+Bullet bheader[100],*beewx[1500];
static int sxcnt,seq,beecnt;
bool brdir;
double offset;
diff --git a/main.cpp b/main.cpp
index c6db4fe..08dbdee 100644
--- a/main.cpp
+++ b/main.cpp
@@ -51,6 +51,7 @@
#include <mmsystem.h>
#endif
#include "libcgh.h"
+#include "hgeft.h"
#include "menuitem.h"
#include "global.h"
#include "music.h"
@@ -711,10 +712,14 @@ bool FrameFunc()
if (Current_Position==13)OptionsGUI->Render();
if (Current_Position==14)PlayerProfGUI->Render();
fnt->SetColor(0xFFFFFFFF);
- fnt->printf(680, 575, HGETEXT_LEFT, "FPS: %d", hge->Timer_GetFPS());
+ //fnt->printf(680, 575, HGETEXT_LEFT, "FPS: %d", hge->Timer_GetFPS());
+ rbPanelFont.UpdateString(L" FPS: %d",hge->Timer_GetFPS());
+ rbPanelFont.Render(785,595,0xFFFFFFFF,1);
if (Current_Position==1||Current_Position==2)
{
- fnt->printf(670,560, HGETEXT_LEFT, "AF: %.2f", averfps);
+ //fnt->printf(670,560, HGETEXT_LEFT, "AF: %.2f", averfps);
+ rbPanelFont.UpdateString(L"AF: %.2f",averfps);
+ rbPanelFont.Render(785,575,0xFFFFFFFF,1);
if (playerpos.x<220&&playerpos.y<200)
{
if (!LOWFPS&&infofade>=0x33)--infofade;
@@ -747,12 +752,12 @@ bool FrameFunc()
}
void printHelp(char *exec,const char* str="")
{
- printf("Usage %s [options]...\n",exec);
+ printf("Usage: %s [options]...\n",exec);
printf("To run the game normally, just start without arguments.\n");
printf("Options:\n");
printf("--help Print this help and exit.\n");
printf("--version Print version and exit.\n");
- printf("--start=x,y Start the game directly from level x part y. The part must be valid.\n");
+ printf("--start=x,y Start free play mode directly from level x part y. The part must be valid.\n");
printf("--nosound Forcibly use no sound.\n");
printf("--fullscreen=1/0 Forcibly use fullscreen/windowed. This will override your configuration.\n");
printf("--firststartup Forcibly run first start up. This will reset the score file.\n");
@@ -944,6 +949,11 @@ int main(int argc,char *argv[])
quad.v[1].x=800; quad.v[1].y=0;
quad.v[2].x=800; quad.v[2].y=600;
quad.v[3].x=0; quad.v[3].y=600;
+#ifdef WIN32
+ rbPanelFont.Init("%SystemRoot%/Fonts/cour.ttf",18);
+#else
+ rbPanelFont.Init("/usr/share/fonts/truetype/freefont/FreeMono.ttf",18);
+#endif
fnt=new hgeFont("./Resources/charmap.fnt");
TipFont=new hgeFont("./Resources/charmap.fnt");
MultFnt=new hgeFont("./Resources/charmap.fnt");