/* initialize the gl , run only once!! params:gtk opgn gl canvas and optional data pointer return value:none */ static void realize(GtkWidget * widget, gpointer data) { GdkGLContext *glcontext = gtk_widget_get_gl_context(widget); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget); /*smyrna does not use any ligthting affects but can be turned on for more effects in the future */ GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat position[] = { 0.0, 3.0, 3.0, 0.0 }; GLfloat lmodel_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat local_view[] = { 0.0 }; static char *smyrna_font; #ifdef WIN32 smyrna_font = "c:/arial.tga"; #else smyrna_font = smyrnaPath("arial.tga"); #endif g_print("loading font....%i\n", fontLoad(smyrna_font)); /*** OpenGL BEGIN ***/ if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) return; glClearColor(view->bgColor.R, view->bgColor.G, view->bgColor.B, view->bgColor.A); //background color glClearDepth(1.0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); glFrontFace(GL_CW); // glEnable (GL_LIGHTING); // glEnable (GL_LIGHT0); // glEnable (GL_AUTO_NORMAL); // glEnable (GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LESS); // glEnable(GL_LINE_SMOOTH); gdk_gl_drawable_gl_end(gldrawable); /*** OpenGL END ***/ return; }
/*----------------------------------------------------------------------------- Name : frReloadFonts Description : reloads all of the currently loaded fonts with respect to the currently selected language. Inputs : none Outputs : none Return : void ----------------------------------------------------------------------------*/ void frReloadFonts(void) { sdword index; fonthandle curfont; char name[64]; char fullName[128]; curfont = fontCurrentGet(); for (index = FR_NumberFonts - 1; index >= 1; index--) { //for all of the registry if (frFontRegistry[index].name != NULL) { // free memory associated with the current font strcpy(name, frFontRegistry[index].name); memFree(frFontRegistry[index].name); //free previously allocated name frFontRegistry[index].name = NULL; //no longer registered fontDiscard(frFontRegistry[index].handle); //free the font frFontRegistry[index].name = memStringDupe(name);//duplicate name string strcpy(fullName, FR_PrependPath); //prepare file path if (strCurLanguage==languageEnglish) { strcat(fullName, FR_English); } else if (strCurLanguage==languageFrench) { strcat(fullName, FR_French); } else if (strCurLanguage==languageGerman) { strcat(fullName, FR_German); } else if (strCurLanguage==languageSpanish) { strcat(fullName, FR_Spanish); } else if (strCurLanguage==languageItalian) { strcat(fullName, FR_Italian); } strcat(fullName, name); frFontRegistry[index].fontdat = fontLoad(fullName); //load file frFontRegistry[index].handle = index; } } fontMakeCurrent(curfont); }
// Function allocates and init a Game static game_p gameNew(engine_p engine, board_p board) { game_p game = NULL; context_p screen = NULL; int hd = 0; ASSERT(NULL != board, "gameNew"); game = (game_p)objectCreate( sizeof(game_t), (destructor_f)gameDestroy); game->board = boardRetain(board); screen = engineScreen(engine); game->width = contextWidth(screen); game->height = contextHeight(screen); game->padding = (game->width < game->height ? game->width : game->height) / 64; hd = engineHDSupported(engine); game->regular = fontRetain( fontLoad(hd ? fontNameRegularHD : fontNameRegularSD)); game->bold = fontRetain(fontLoad( hd ? fontNameBoldHD : fontNameBoldSD)); game->status_line = MAX(fontLine(game->regular), fontLine(game->bold)); game->images[0] = imageRetain( imageLoad(hd ? imageNameEmptyHD : imageNameEmptySD)); game->images[1] = imageRetain(imageLoad( hd ? imageName2HD : imageName2SD)); game->images[2] = imageRetain(imageLoad( hd ? imageName4HD : imageName4SD)); game->images[3] = imageRetain(imageLoad( hd ? imageName8HD : imageName8SD)); game->images[4] = imageRetain(imageLoad( hd ? imageName16HD : imageName16SD)); game->images[5] = imageRetain(imageLoad( hd ? imageName32HD : imageName32SD)); game->images[6] = imageRetain(imageLoad( hd ? imageName64HD : imageName64SD)); game->images[7] = imageRetain(imageLoad( hd ? imageName128HD : imageName128SD)); game->images[8] = imageRetain(imageLoad( hd ? imageName256HD : imageName256SD)); game->images[9] = imageRetain(imageLoad( hd ? imageName512HD : imageName512SD)); game->images[10] = imageRetain(imageLoad( hd ? imageName1024HD : imageName1024SD)); game->images[11] = imageRetain(imageLoad( hd ? imageName2048HD : imageName2048SD)); game->images[12] = imageRetain(imageLoad( hd ? imageName4096HD : imageName4096SD)); game->images[13] = imageRetain(imageLoad( hd ? imageName8192HD : imageName8192SD)); game->images[14] = imageRetain( imageLoad(hd ? imageName16384HD : imageName16384SD)); game->images[15] = imageRetain( imageLoad(hd ? imageName32768HD : imageName32768SD)); game->images[16] = imageRetain( imageLoad(hd ? imageName65536HD : imageName65536SD)); game->images[17] = imageRetain( imageLoad(hd ? imageName131072HD : imageName131072SD)); game->cell = MIN(imageWidth(game->images[0]), imageHeight(game->images[0])); game->board_back = rgbColor(0xBB, 0xAD, 0xA0); return game; };
/*----------------------------------------------------------------------------- Name : frFontRegister Description : Register usage of a font, loading it if needed Inputs : Outputs : Return : ----------------------------------------------------------------------------*/ fonthandle frFontRegister(char *fileName) { sdword index, freeIndex = -1; char fullName[80]; for (index = FR_NumberFonts - 1; index >= 1; index--) { //for all of the registry if (frFontRegistry[index].name == NULL) { //if this one free freeIndex = index; } else { if (frNamesCompare(fileName, frFontRegistry[index].name)) { //if this is the font you want #if FR_VERBOSE_LEVEL >= 2 dbgMessagef("frFontRegister: Returning pre-registered font %s with usage count of %d", frFontRegistry[index].name, frFontRegistry[index].nUsageCount); #endif frFontRegistry[index].nUsageCount++; //increment usage count return(index); //return pre-loaded handle } } } #if FR_ERROR_CHECKING if (freeIndex == -1) { dbgFatalf(DBG_Loc, "Font registry not big enough for %s, only %d long", fileName, FR_NumberFonts); } #endif #if FR_VERBOSE_LEVEL >= 1 dbgMessagef("frFontRegister: Font %s not pre-registered, loading now...", fileName); #endif frFontRegistry[freeIndex].name = memStringDupe(fileName);//duplicate name string frFontRegistry[freeIndex].nUsageCount = 1; //start usage count at 1 strcpy(fullName, FR_PrependPath); //prepare file path if (strCurLanguage==languageEnglish) { strcat(fullName, FR_English); } else if (strCurLanguage==languageFrench) { strcat(fullName, FR_French); } else if (strCurLanguage==languageGerman) { strcat(fullName, FR_German); } else if (strCurLanguage==languageSpanish) { strcat(fullName, FR_Spanish); } else if (strCurLanguage==languageItalian) { strcat(fullName, FR_Italian); } strcat(fullName, fileName); frFontRegistry[freeIndex].fontdat = fontLoad(fullName); //load file frFontRegistry[freeIndex].handle = freeIndex; return(freeIndex); }