From faa75e3a202b773d5f90cd99bc076ca9635440bf Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sun, 6 Aug 2006 03:16:23 +0000 Subject: Added Text rendering support via QuesoGLC (http://quesoglc.sourceforge.net/index.html). git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@11 4dd1920e-271a-0410-bca0-81b404a81564 --- Makefile | 2 +- glpong3d.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++------------- glpong3d.h | 2 ++ 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index d5d133f..0dee9ba 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ WARN=-Wall -W -ansi -pedantic CFLAGS=-Os -pipe -std=c99 ${WARN} LDFLAGS=-Wl,-O1,-s INCLUDES=`sdl-config --cflags` -LIBRARIES=`sdl-config --libs` -lSDL_image -lGL -lGLU +LIBRARIES=`sdl-config --libs` -lSDL_image -lSDL_net -lGL -lGLU -lGLC EXT=.exe EXE=glpong3d${EXT} diff --git a/glpong3d.c b/glpong3d.c index b9aee6c..2203f39 100644 --- a/glpong3d.c +++ b/glpong3d.c @@ -5,10 +5,14 @@ #include "SDL.h" #include "SDL_opengl.h" #include "SDL_image.h" +#include "SDL_net.h" +#include #include "glpong3d.h" GLuint box; +GLuint font; +GLuint ctx; int main(int argc, char * argv[]) { if (argc) { @@ -30,6 +34,8 @@ int main(int argc, char * argv[]) { void GLPong_Init() { SDL_Surface * temp = NULL; + int i; + int count; GLPong.done = 0; @@ -41,8 +47,8 @@ void GLPong_Init() { GLPong.Ball.x = -(GLPong.Ball.w / 2); GLPong.Ball.y = -(GLPong.Ball.h / 2); GLPong.Ball.z = -3.0f; - GLPong.Ball.xv = 0.0f; - GLPong.Ball.yv = 0.0f; + GLPong.Ball.xv = 0.02f; + GLPong.Ball.yv = 0.01f; GLPong.Ball.zv = -0.03f; GLPong.Front.w = 0.66f; @@ -57,9 +63,28 @@ void GLPong_Init() { GLPong.Back.y = -(GLPong.Front.h / 2); GLPong.Back.z = -9.0f; + ctx = glcGenContext(); + glcContext(ctx); +#ifdef _WIN32 + glcAppendCatalog("C:\\WINDOWS\\Fonts"); +#endif + count = glcGeti(GLC_CATALOG_COUNT); + for (i = 0; i < count; i++) { + printf("%s\n", glcGetListc(GLC_CATALOG_LIST, i)); + } + + font = glcGenFontID(); + glcNewFontFromFamily(font, "DejaVu Sans"); + glcFontFace(font, "Normal"); + glcRenderStyle(GLC_TEXTURE); + glcFont(font); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); atexit(SDL_Quit); + SDLNet_Init(); + atexit(SDLNet_Quit); + SDL_WM_SetCaption("glpong3d", "glpong3d"); temp = IMG_Load("ball.png"); SDL_WM_SetIcon(temp, NULL); @@ -243,10 +268,10 @@ void GLPong_Draw() { glColor3f(1.0f, 1.0f, 1.0f); glTranslatef(0.0f, 0.0f, GLPong.Back.z); glBegin(GL_QUADS); - glTexCoord2f(0.168f, 1.0f); glVertex2f(GLPong.Back.w / 2, GLPong.Back.h / 2); /* Upper Right */ - glTexCoord2f(0.832f, 1.0f); glVertex2f(-GLPong.Back.w / 2, GLPong.Back.h / 2); /* Upper Left */ - glTexCoord2f(0.832f, 0.0f); glVertex2f(-GLPong.Back.w / 2, -GLPong.Back.h / 2); /* Lower Left */ - glTexCoord2f(0.168f, 0.0f); glVertex2f(GLPong.Back.w / 2, -GLPong.Back.h / 2); /* Lower Right */ + glTexCoord2f(0.832f, 1.0f); glVertex2f(GLPong.Back.w / 2, GLPong.Back.h / 2); /* Upper Right */ + glTexCoord2f(0.168f, 1.0f); glVertex2f(-GLPong.Back.w / 2, GLPong.Back.h / 2); /* Upper Left */ + glTexCoord2f(0.168f, 0.0f); glVertex2f(-GLPong.Back.w / 2, -GLPong.Back.h / 2); /* Lower Left */ + glTexCoord2f(0.832f, 0.0f); glVertex2f(GLPong.Back.w / 2, -GLPong.Back.h / 2); /* Lower Right */ glEnd(); glDisable(GL_TEXTURE_2D); @@ -254,7 +279,6 @@ void GLPong_Draw() { glBindTexture(GL_TEXTURE_2D, ball_texture); glEnable(GL_TEXTURE_2D); glTranslatef(GLPong.Ball.x, GLPong.Ball.y, GLPong.Ball.z); - /*glRotatef(GLPong.Ball.rotate, 0.0f, 0.0f, 1.0f);*/ glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2f(GLPong.Ball.w, GLPong.Ball.h); /* Lower Left */ glTexCoord2f(1.0f, 1.0f); glVertex2f(0.0f, GLPong.Ball.h); /* Lower Right */ @@ -279,6 +303,13 @@ void GLPong_Draw() { glEnd(); glDisable(GL_TEXTURE_2D); + glLoadIdentity(); + glTranslatef(0.0f, 1.1f, -3.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glScalef(0.1f, 0.1f, 0.0f); + glcRenderString("Hello, GLC"); + glDisable2D(); + SDL_GL_SwapBuffers(); } @@ -299,10 +330,6 @@ void GLPong_Move() { if ((GLPong.Ball.z < -9.0f) || (GLPong.Ball.z > -3.0f)) { GLPong.Ball.zv = -GLPong.Ball.zv; } - /*GLPong.Ball.rotate += 2.0f; - if (GLPong.Ball.rotate >= 360.f) { - GLPong.Ball.rotate -= 360.0f; - }*/ } __inline__ unsigned int NextPow2(unsigned int value) { @@ -336,20 +363,15 @@ GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface) { if (surface->format->Rmask & rmask) { format = GL_RGB; - printf("GL_RGB"); if (surface->format->BitsPerPixel == 32) { format = GL_RGBA; - printf("A"); } } else if (surface->format->Rmask & bmask) { format = GL_BGR; - printf("GL_BGR"); if (surface->format->BitsPerPixel == 32) { format = GL_BGRA; - printf("A"); } } - printf("\n"); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); @@ -363,3 +385,25 @@ GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface) { return texture; } + +void glEnable2D() { + int vPort[4]; + + glGetIntegerv(GL_VIEWPORT, vPort); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glOrtho(0, vPort[2], vPort[3], 0, -1, 1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); +} + +void glDisable2D() { + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} diff --git a/glpong3d.h b/glpong3d.h index dad9526..a248b7c 100644 --- a/glpong3d.h +++ b/glpong3d.h @@ -33,5 +33,7 @@ void GLPong_Move(); GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface); __inline__ unsigned int NextPow2(unsigned int value); +void glEnable2D(); +void glDisable2D(); #endif -- cgit v1.2.3