void init_opengl(void) { //OpenGL initialization glViewport(0, 0, window_width, window_height); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Set 2D mode (no perspective) glOrtho(0, window_width, 0, window_height, -1, 1); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); //Set the screen background color glClearColor(1.0, 1.0, 1.0, 1.0); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); }
void GameMenu(Game *game, int w, int h) { static int si = 0; if (si == 0) { initialize_fonts(); si++; } //Game Menu glBegin(GL_LINES); Rect r; r.bot = h - 10; r.left = 10; r.center = 0; ggprint8b(&r, 16, 0, ""); ggprint8b(&r, 16, 0, "Toggles - N: Nick, L: Lizandro, C: Charles, R: Roy"); ggprint8b(&r, 16, 0, "Spacebar - Reload"); ggprint8b(&r, 16, 0, "Left click - Shoot"); ggprint8b(&r, 16, 0, "1 - 9mm"); ggprint8b(&r, 16, 0, "2 - Sniper"); ggprint8b(&r, 16, 0, "3 - ShotGun"); ggprint8b(&r, 16, 0, "Nround: %i / %i", game->nbullets, game->maxbullets); ggprint8b(&r, 16, 0, "Kills: %i", game->nkills); ggprint8b(&r, 16, 0, "Player: %s", game->name); // ggprint8b(&r, 16, 0, "Score: Sounds"); glEnd(); }
void initXWindows(void) { //do not change GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; int w=WINDOW_WIDTH, h=WINDOW_HEIGHT; dpy = XOpenDisplay(NULL); if (dpy == NULL) { std::cout << "\n\tcannot connect to X server\n" << std::endl; exit(EXIT_FAILURE); } Window root = DefaultRootWindow(dpy); XVisualInfo *vi = glXChooseVisual(dpy, 0, att); if(vi == NULL) { std::cout << "\n\tno appropriate visual found\n" << std::endl; exit(EXIT_FAILURE); } Colormap cmap = XCreateColormap(dpy, root, vi->visual, AllocNone); XSetWindowAttributes swa; swa.colormap = cmap; swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPress | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | SubstructureNotifyMask; win = XCreateWindow(dpy, root, 0, 0, w, h, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa); set_title(); glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); glXMakeCurrent(dpy, win, glc); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Set 2D mode (no perspective) glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); //Set the screen background color glClearColor(0.1, 0.1, 0.1, 1.0); glEnable(GL_TEXTURE_2D); initialize_fonts(); }
void register_graph (lua_State *L) { pthread_mutex_init (agg_mutex, NULL); window_registry_prepare (L); luaL_register (L, MLUA_GRAPHLIBNAME, methods_dummy); draw_register (L); text_register (L); app_window_hooks->register_module (L); plot_register (L); initialize_fonts (L); lua_pop(L, 1); }
void init_character_boxes(void) { int w,h; glViewport(0, 0, xres, yres); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //This sets 2D mode (no perspective) glOrtho(0, xres, 0, yres, -1, 1); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); glClearColor(1.0, 1.0, 1.0, 1.0); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); /*********** Initialize Textures *************************/ /*GUILE CHARACTER BOX TEXTURE*/ char b[] = "./images/selectGuile.ppm"; guileImage = ppm6GetImage(guileImage, b); glGenTextures(1, &guileTexture); glBindTexture(GL_TEXTURE_2D, guileTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); w = guileImage->width; h = guileImage->height; unsigned char *guileData = buildAlphaData(guileImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, guileData); delete [] guileData; /********** Initialize Box Position (s) **********/ charBox1.pos[0] = 200; charBox1.pos[1] = 300; charBox1.width = 200; charBox1.height = 300; }
SubtitleRenderer:: SubtitleRenderer(int layer, const std::string& font_path, float font_size, float margin_left, float margin_bottom, bool centered, unsigned int white_level, unsigned int box_opacity) : prepared_(), dispman_element_(), dispman_display_(), screen_width_(), screen_height_(), display_(), context_(), surface_(), vg_font_(), vg_font_border_(), vg_font_italic_(), vg_font_italic_border_(), ft_library_(), ft_face_(), ft_stroker_(), line_height_(), box_offset_(), box_h_padding_(), margin_left_(margin_left), margin_bottom_(margin_bottom), centered_(centered), white_level_(white_level), box_opacity_(box_opacity) { try { initialize_window(layer); initialize_egl(); initialize_fonts(font_path, font_size); } catch (...) { destroy(); throw; } }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, xres, yres); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //This sets 2D mode (no perspective) glOrtho(0, xres, 0, yres, -1, 1); // glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); // //Clear the screen to black glClearColor(0.0, 0.0, 0.0, 1.0); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); }
int main(void) { initXWindows(); srand(time(NULL)); clock_gettime(CLOCK_REALTIME, &timePause); clock_gettime(CLOCK_REALTIME, &timeStart); init_opengl(); init_ship(); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); init_textures(); while(!done) { while(XPending(dpy)) { XEvent e; XNextEvent(dpy, &e); check_resize(&e); check_mouse(&e); check_keys(&e); } clock_gettime(CLOCK_REALTIME, &timeCurrent); timeSpan = timeDiff(&timeStart, &timeCurrent); timeCopy(&timeStart, &timeCurrent); physicsCountdown += timeSpan; while (physicsCountdown >= physicsRate) { physics(); physicsCountdown -= physicsRate; render(); } //physics(); //render(); glXSwapBuffers(dpy, win); } cleanupXWindows(); cleanup_fonts(); return 0; }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, xres, yres); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //This sets 2D mode (no perspective) glOrtho(0, xres, 0, yres, -1, 1); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); //Clear the screen glClearColor(1.0, 1.0, 1.0, 1.0); //glClear(GL_COLOR_BUFFER_BIT); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); // //load the images file into a ppm structure. // kangarooImage = ppm6GetImage("./images/ricky.ppm"); levelImage = ppm6GetImage("./images/LevelBlack.ppm"); mountainsImage = ppm6GetImage("./images/BackBlack.ppm"); startImage = ppm6GetImage("./images/start.ppm"); whiteImage = ppm6GetImage("./images/white.ppm"); gameoverImage = ppm6GetImage("./images/wasted.ppm"); //------------------------------------------------------- rhinoImage = ppm6GetImage("./images/rhino.ppm"); animalImage = ppm6GetImage("./images/altrhino.ppm"); /*ufoImage = ppm6GetImage("./images/ufo.ppm");*/ // //create opengl texture elements glGenTextures(1, &RhinoTexture); glGenTextures(1, &AnimalTexture); glGenTextures(1, &KangarooTexture); glGenTextures(1, &LevelTexture); glGenTextures(1, &MountainTexture); glGenTextures(1, &StartTexture); glGenTextures(1, &WhiteTexture); glGenTextures(1, &GameOverTexture); //----------------------------------------------------------------- //------------------------------------------------------------------------- // // Kangaroo // int w = kangarooImage->width; int h = kangarooImage->height; glBindTexture(GL_TEXTURE_2D, KangarooTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... unsigned char *Transparent = buildAlphaData(kangarooImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, Transparent); free(Transparent); //------------------------------------------------------------------------- // // Kangaroo - Punch // init_punch_texture(w,h); //------------------------------------------------------------------------- // // Kangaroo - Hop // init_hop_texture(w,h); //------------------------------------------------------------------------- // // Rhino // int w1 = rhinoImage->width; int h1 = rhinoImage->height; glBindTexture(GL_TEXTURE_2D, RhinoTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... Transparent = buildAlphaData(rhinoImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w1, h1, 0, GL_RGBA, GL_UNSIGNED_BYTE, Transparent); free(Transparent); //------------------------------------------------------------------------- // // Animal // int w2 = animalImage->width; int h2 = animalImage->height; glBindTexture(GL_TEXTURE_2D, AnimalTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... Transparent = buildAlphaData(animalImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2, h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, Transparent); free(Transparent); //------------------------------------------------------------------------- // // UFO Spaceship // ufoOpenGL(); /*int w3 = ufoImage->width; int h3 = ufoImage->height; glBindTexture(GL_TEXTURE_2D, UFOTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... Transparent = buildAlphaData(ufoImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w3, h3, 0, GL_RGBA, GL_UNSIGNED_BYTE, Transparent); free(Transparent);*/ //------------------------------------------------------------------------- // // Background - Platforms // glBindTexture(GL_TEXTURE_2D, LevelTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... Transparent = buildAlphaData(levelImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, levelImage->width, levelImage->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Transparent); free(Transparent); //------------------------------------------------------------------------- // // Background - Mountains // glBindTexture(GL_TEXTURE_2D, MountainTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... Transparent = buildAlphaData(mountainsImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mountainsImage->width, mountainsImage->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Transparent); free(Transparent); //------------------------------------------------------------------------- // // Start Page // glBindTexture(GL_TEXTURE_2D, StartTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, startImage->width, startImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, startImage->data); //------------------------------------------------------------------------- // // Death flash // glBindTexture(GL_TEXTURE_2D, WhiteTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, whiteImage->width, whiteImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, whiteImage->data); //------------------------------------------------------------------------- // // Gameover // glBindTexture(GL_TEXTURE_2D, GameOverTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, gameoverImage->width, gameoverImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, gameoverImage->data); //------------------------------------------------------------------------- }
void render(Game *game) { //upper-left and lower-right corners of a rectangle Rect rct; float w, h; glClear(GL_COLOR_BUFFER_BIT); //Draw shapes... //draw box Shape *s; glColor3ub(90,140,90); for (int i = 0; i < 5; i++) { s = &game->box[i]; glPushMatrix(); glTranslatef(s->center.x, s->center.y, s->center.z); w = s->width; h = s->height; glBegin(GL_QUADS); glVertex2i(-w,-h); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w,-h); glEnd(); glPopMatrix(); } const int n = 60; static Vec verts[n]; static int firsttime = 1; float angle = 0.0; if (firsttime) { float incr = (PI * 2.0) / (float) n; for (int i = 0; i < n; i++) { verts[i].y = sin(angle) * game->circle.radius; verts[i].x = cos(angle) * game->circle.radius; angle += incr; } firsttime = 0; } //glColor3ub(90, 140, 90); //glPushMatric(); glBegin(GL_TRIANGLE_FAN); for (int i = 0; i < n; i++) { glVertex2i(game->circle.center.x + verts[i].x, game->circle.center.y + verts[i].y); } glEnd(); //glPopMatrix(); //draw all particles here //for (int i = 0; i < game->n; i++) { glPushMatrix(); //glColor3ub(rnd() * 150, rnd() * 160, rnd() * 220); for (int i = 0; i < game-> n; i++) { glColor3ub(rnd() * 150, rnd() * 160, rnd() * 220); Vec *c = &game->particle[i].s.center; w = 2; h = 2; glBegin(GL_QUADS); glVertex2i(c->x-w, c->y-h); glVertex2i(c->x-w, c->y+h); glVertex2i(c->x+w, c->y+h); glVertex2i(c->x+w, c->y-h); glEnd(); glPopMatrix(); } //glPopMatrix(); //} //texts/fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); rct.bot = 585; rct.left = 90; ggprint8b (&rct, 16, 0x99CCFF, "Waterfall Model."); rct.bot = 570; rct.left = 100; ggprint8b (&rct, 16, 0x00ffff0, "Press b for bubbler."); rct.bot = 490; rct.left = 100; rct.center = 1; ggprint16 (&rct, 16, 0xFF0099, "Requirements."); rct.bot = 428; rct.left = 150; ggprint16 (&rct, 16, 0xFF0099, "Design."); rct.bot -= 45; rct.left += 70; ggprint16 (&rct, 16, 0xFF0099, "Coding."); rct.bot -= 45; rct.left += 70; ggprint16 (&rct, 16, 0xFF0099, "Testing."); rct.bot -= 40; rct.left += 90; ggprint16 (&rct, 16, 0xFF0099, "Maintenance."); //if(bubble) { //if (game->n < MAX_PARTICLES) { //for (int i = 0; i < 10; i++) { //makeParticle(game, 120, 550); //} //} //} }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Set 2D mode (no perspective) glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); //added for background glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); //clear the screen glClearColor(1.0, 1.0, 1.0, 1.0); backgroundImage = ppm6GetImage("./images/background.ppm"); backgroundTransImage = ppm6GetImage("./images/backgroundTrans.ppm"); gameoverbgImage = ppm6GetImage("./images/gameoverbg.ppm"); //------------------------------------------------------------------- //bullet glGenTextures(1, &bulletTexture); bulletImage = ppm6GetImage("./images/bullet.ppm"); int w3 = bulletImage->width; int h3 = bulletImage->height; glBindTexture(GL_TEXTURE_2D, bulletTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w3, h3, 0, GL_RGB, GL_UNSIGNED_BYTE, bulletImage->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //White duck score sprite glGenTextures(1, &duckscoreTexture); duckscoreImage = ppm6GetImage("./images/duck_score_1.ppm"); int w4 = duckscoreImage->width; int h4 = duckscoreImage->height; glBindTexture(GL_TEXTURE_2D, duckscoreTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w4, h4, 0, GL_RGB, GL_UNSIGNED_BYTE, duckscoreImage->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //Red duck score sprite glGenTextures(1, &duckscoreTexture2); duckscoreImage2 = ppm6GetImage("./images/duck_score_2.ppm"); int w5 = duckscoreImage2->width; int h5 = duckscoreImage2->height; glBindTexture(GL_TEXTURE_2D, duckscoreTexture2); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w5, h5, 0, GL_RGB, GL_UNSIGNED_BYTE, duckscoreImage2->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //duck sprite glGenTextures(1, &duckTexture); glGenTextures(1, &duckSil); duckImage = ppm6GetImage("./images/ducks1.ppm"); int w = duckImage->width; int h = duckImage->height; glBindTexture(GL_TEXTURE_2D, duckTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, duckImage->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //duck sprite 2 glGenTextures(1, &duckTexture2); glGenTextures(1, &duckSil2); duckImage2 = ppm6GetImage("./images/duck2.ppm"); int w2 = duckImage2->width; int h2 = duckImage2->height; glBindTexture(GL_TEXTURE_2D, duckTexture2); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w2, h2, 0, GL_RGB, GL_UNSIGNED_BYTE, duckImage2->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //duck sprite 3 glGenTextures(1, &duckTexture3); glGenTextures(1, &duckSil3); duckImage3 = ppm6GetImage("./images/shotduck1.ppm"); int w6 = duckImage3->width; int h6 = duckImage3->height; glBindTexture(GL_TEXTURE_2D, duckTexture3); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w6, h6, 0, GL_RGB, GL_UNSIGNED_BYTE, duckImage3->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //duck sprite 4 glGenTextures(1, &duckTexture4); glGenTextures(1, &duckSil4); duckImage4 = ppm6GetImage("./images/shotduck2.ppm"); int w7 = duckImage4->width; int h7 = duckImage4->height; glBindTexture(GL_TEXTURE_2D, duckTexture4); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w7, h7, 0, GL_RGB, GL_UNSIGNED_BYTE, duckImage4->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //duck sprite 5 glGenTextures(1, &duckTexture5); glGenTextures(1, &duckSil5); duckImage5 = ppm6GetImage("./images/ducks2.ppm"); int w8 = duckImage5->width; int h8 = duckImage5->height; glBindTexture(GL_TEXTURE_2D, duckTexture5); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w8, h8, 0, GL_RGB, GL_UNSIGNED_BYTE, duckImage5->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //duck silhouette glBindTexture(GL_TEXTURE_2D, duckSil); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData = buildAlphaData(duckImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData); delete [] silhouetteData; //------------------------------------------------------------------- //------------------------------------------------------------------- //duck silhouette 2 glBindTexture(GL_TEXTURE_2D, duckSil2); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData2 = buildAlphaData(duckImage2); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2, h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData2); delete [] silhouetteData2; //------------------------------------------------------------------- //------------------------------------------------------------------- //duck silhouette 3 glBindTexture(GL_TEXTURE_2D, duckSil3); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData3 = buildAlphaData(duckImage3); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w6, h6, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData3); delete [] silhouetteData3; //------------------------------------------------------------------- //------------------------------------------------------------------- //duck silhouette 4 glBindTexture(GL_TEXTURE_2D, duckSil4); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData4 = buildAlphaData(duckImage4); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w7, h7, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData4); delete [] silhouetteData4; //------------------------------------------------------------------- //------------------------------------------------------------------- //duck silhouette 5 glBindTexture(GL_TEXTURE_2D, duckSil5); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData5 = buildAlphaData(duckImage5); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w8, h8, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData5); delete [] silhouetteData5; //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog sprite 1 glGenTextures(1, &dogTexture1); glGenTextures(1, &dogSil1); dogImage1 = ppm6GetImage("./images/dogs1.ppm"); int w10 = dogImage1->width; int h10 = dogImage1->height; glBindTexture(GL_TEXTURE_2D, dogTexture1); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w10, h10, 0, GL_RGB, GL_UNSIGNED_BYTE, dogImage1->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog sprite 2 glGenTextures(1, &dogTexture2); glGenTextures(1, &dogSil2); dogImage2 = ppm6GetImage("./images/dogs21.ppm"); int w11 = dogImage2->width; int h11 = dogImage2->height; glBindTexture(GL_TEXTURE_2D, dogTexture2); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w11, h11, 0, GL_RGB, GL_UNSIGNED_BYTE, dogImage2->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog sprite 3 glGenTextures(1, &dogTexture3); glGenTextures(1, &dogSil3); dogImage3 = ppm6GetImage("./images/dogs3.ppm"); int w12 = dogImage3->width; int h12 = dogImage3->height; glBindTexture(GL_TEXTURE_2D, dogTexture3); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w12, h12, 0, GL_RGB, GL_UNSIGNED_BYTE, dogImage3->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog sprite 4 glGenTextures(1, &dogTexture4); glGenTextures(1, &dogSil4); dogImage4 = ppm6GetImage("./images/dog1.ppm"); int w17 = dogImage4->width; int h17 = dogImage4->height; glBindTexture(GL_TEXTURE_2D, dogTexture4); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w17, h17, 0, GL_RGB, GL_UNSIGNED_BYTE, dogImage4->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog silhouette 4 glBindTexture(GL_TEXTURE_2D, dogSil4); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData17 = buildAlphaData(dogImage4); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w17, h17, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData17); delete [] silhouetteData17; //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog silhouette 1 glBindTexture(GL_TEXTURE_2D, dogSil1); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData6 = buildAlphaData(dogImage1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w10, h10, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData6); delete [] silhouetteData6; //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog silhouette 2 glBindTexture(GL_TEXTURE_2D, dogSil2); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData7 = buildAlphaData(dogImage2); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w11, h11, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData7); delete [] silhouetteData7; //------------------------------------------------------------------- //------------------------------------------------------------------- //Dog silhouette 3 glBindTexture(GL_TEXTURE_2D, dogSil3); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); ////must build a new set of data... unsigned char *silhouetteData8 = buildAlphaData(dogImage3); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w12, h12, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData8); delete [] silhouetteData8; //------------------------------------------------------------------- //------------------------------------------------------------------- //background textures //create opengl texture elements glGenTextures(1, &backgroundTexture); glBindTexture(GL_TEXTURE_2D, backgroundTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, backgroundImage->width, backgroundImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, backgroundImage->data); //------------------------------------------------------------------- //------------------------------------------------------------------- //No genTextures for trans image? //forest transparent part glBindTexture(GL_TEXTURE_2D, backgroundTransTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); //must build a new set of data... int w15 = backgroundTransImage->width; int h15 = backgroundTransImage->height; unsigned char *ftData = buildAlphaData(backgroundTransImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w15, h15, 0, GL_RGBA, GL_UNSIGNED_BYTE, ftData); delete [] ftData; //------------------------------------------------------------------- //------------------------------------------------------------------- //gameover glGenTextures(1, &gameoverbgTexture); glBindTexture(GL_TEXTURE_2D, gameoverbgTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, gameoverbgImage->width, gameoverbgImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, gameoverbgImage->data); //------------------------------------------------------------------- glEnable(GL_TEXTURE_2D); initialize_fonts(); }
static void initialize_application(void) { #if defined(__WIN32__) && defined(__MINGW32__) if (LoadLibrary("exchndl.dll")) option_debug = true; #endif // SDL_putenv(const_cast<char*>("SDL_VIDEO_ALLOW_SCREENSAVER=1")); // Initialize SDL int retval = SDL_Init(SDL_INIT_VIDEO | (option_nosound ? 0 : SDL_INIT_AUDIO) | (option_nojoystick ? 0 : SDL_INIT_JOYSTICK) | (option_debug ? SDL_INIT_NOPARACHUTE : 0)); if (retval < 0) { const char *sdl_err = SDL_GetError(); if (sdl_err) fprintf(stderr, "Couldn't initialize SDL (%s)\n", sdl_err); else fprintf(stderr, "Couldn't initialize SDL\n"); exit(1); } #if defined(HAVE_SDL_IMAGE) IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG); #endif // We only want text input events at specific times SDL_StopTextInput(); // Find data directories, construct search path InitDefaultStringSets(); #if defined(unix) || defined(__NetBSD__) || defined(__OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && !defined(HAVE_BUNDLE_NAME)) default_data_dir = PKGDATADIR; const char *home = getenv("HOME"); if (home) local_data_dir = home; local_data_dir += ".alephone"; log_dir = local_data_dir; #elif defined(__APPLE__) && defined(__MACH__) bundle_data_dir = bundle_resource_path; bundle_data_dir += "DataFiles"; data_search_path.push_back(bundle_data_dir); #ifndef SCENARIO_IS_BUNDLED { char* buf = getcwd(0, 0); default_data_dir = buf; free(buf); } #endif log_dir = app_log_directory; preferences_dir = app_preferences_directory; local_data_dir = app_support_directory; #elif defined(__WIN32__) char file_name[MAX_PATH]; GetModuleFileName(NULL, file_name, sizeof(file_name)); char *sep = strrchr(file_name, '\\'); *sep = '\0'; default_data_dir = file_name; char login[17]; DWORD len = 17; bool hasName = (GetUserName((LPSTR) login, &len) == TRUE); if (!hasName || strpbrk(login, "\\/:*?\"<>|") != NULL) strcpy(login, "Bob User"); DirectorySpecifier legacy_data_dir = file_name; legacy_data_dir += "Prefs"; legacy_data_dir += login; SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, file_name); local_data_dir = file_name; local_data_dir += "AlephOne"; log_dir = local_data_dir; #else default_data_dir = ""; local_data_dir = ""; //#error Data file paths must be set for this platform. #endif #if defined(__WIN32__) #define LIST_SEP ';' #else #define LIST_SEP ':' #endif // in case we need to redo search path later: size_t dsp_insert_pos = data_search_path.size(); size_t dsp_delete_pos = (size_t)-1; if (arg_directory != "") { default_data_dir = arg_directory; dsp_delete_pos = data_search_path.size(); data_search_path.push_back(arg_directory); } const char *data_env = getenv("ALEPHONE_DATA"); if (data_env) { // Read colon-separated list of directories string path = data_env; string::size_type pos; while ((pos = path.find(LIST_SEP)) != string::npos) { if (pos) { string element = path.substr(0, pos); data_search_path.push_back(element); } path.erase(0, pos + 1); } if (!path.empty()) data_search_path.push_back(path); } else { if (arg_directory == "") { dsp_delete_pos = data_search_path.size(); data_search_path.push_back(default_data_dir); } #if defined(__WIN32__) data_search_path.push_back(legacy_data_dir); #endif data_search_path.push_back(local_data_dir); } // Subdirectories #if defined(__MACH__) && defined(__APPLE__) DirectorySpecifier legacy_preferences_dir = local_data_dir; #elif defined(__WIN32__) DirectorySpecifier legacy_preferences_dir = legacy_data_dir; SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, file_name); preferences_dir = file_name; preferences_dir += "AlephOne"; #else preferences_dir = local_data_dir; #endif saved_games_dir = local_data_dir + "Saved Games"; quick_saves_dir = local_data_dir + "Quick Saves"; image_cache_dir = local_data_dir + "Image Cache"; recordings_dir = local_data_dir + "Recordings"; screenshots_dir = local_data_dir + "Screenshots"; #if defined(__APPLE__) && defined(__MACH__) if (app_screenshots_directory) screenshots_dir = app_screenshots_directory; #endif DirectorySpecifier local_mml_dir = local_data_dir + "MML"; DirectorySpecifier local_themes_dir = local_data_dir + "Themes"; // Setup resource manager initialize_resources(); init_physics_wad_data(); initialize_fonts(false); load_film_profile(FILM_PROFILE_DEFAULT, false); // Parse MML files LoadBaseMMLScripts(); // Check for presence of strings if (!TS_IsPresent(strERRORS) || !TS_IsPresent(strFILENAMES)) { fprintf(stderr, "Can't find required text strings (missing MML?).\n"); exit(1); } // Check for presence of files (one last chance to change data_search_path) if (!have_default_files()) { char chosen_dir[256]; if (alert_choose_scenario(chosen_dir)) { // remove original argument (or fallback) from search path if (dsp_delete_pos < data_search_path.size()) data_search_path.erase(data_search_path.begin() + dsp_delete_pos); // add selected directory where command-line argument would go data_search_path.insert(data_search_path.begin() + dsp_insert_pos, chosen_dir); default_data_dir = chosen_dir; // Parse MML files again, now that we have a new dir to search initialize_fonts(false); LoadBaseMMLScripts(); } } initialize_fonts(true); Plugins::instance()->enumerate(); #if defined(__WIN32__) || (defined(__MACH__) && defined(__APPLE__)) preferences_dir.CreateDirectory(); transition_preferences(legacy_preferences_dir); #endif // Load preferences initialize_preferences(); local_data_dir.CreateDirectory(); saved_games_dir.CreateDirectory(); quick_saves_dir.CreateDirectory(); { std::string scen = Scenario::instance()->GetName(); if (scen.length()) scen.erase(std::remove_if(scen.begin(), scen.end(), char_is_not_filesafe), scen.end()); if (!scen.length()) scen = "Unknown"; quick_saves_dir += scen; quick_saves_dir.CreateDirectory(); } image_cache_dir.CreateDirectory(); recordings_dir.CreateDirectory(); screenshots_dir.CreateDirectory(); local_mml_dir.CreateDirectory(); local_themes_dir.CreateDirectory(); WadImageCache::instance()->initialize_cache(); #ifndef HAVE_OPENGL graphics_preferences->screen_mode.acceleration = _no_acceleration; #endif if (force_fullscreen) graphics_preferences->screen_mode.fullscreen = true; if (force_windowed) // takes precedence over fullscreen because windowed is safer graphics_preferences->screen_mode.fullscreen = false; write_preferences(); Plugins::instance()->load_mml(); // SDL_WM_SetCaption(application_name, application_name); // #if defined(HAVE_SDL_IMAGE) && !(defined(__APPLE__) && defined(__MACH__)) // SDL_WM_SetIcon(IMG_ReadXPMFromArray(const_cast<char**>(alephone_xpm)), 0); // #endif atexit(shutdown_application); #if !defined(DISABLE_NETWORKING) // Initialize SDL_net if (SDLNet_Init () < 0) { fprintf (stderr, "Couldn't initialize SDL_net (%s)\n", SDLNet_GetError()); exit(1); } #endif if (TTF_Init() < 0) { fprintf (stderr, "Couldn't initialize SDL_ttf (%s)\n", TTF_GetError()); exit(1); } HTTPClient::Init(); // Initialize everything mytm_initialize(); // initialize_fonts(); SoundManager::instance()->Initialize(*sound_preferences); initialize_marathon_music_handler(); initialize_keyboard_controller(); initialize_gamma(); alephone::Screen::instance()->Initialize(&graphics_preferences->screen_mode); initialize_marathon(); initialize_screen_drawing(); initialize_dialogs(); initialize_terminal_manager(); initialize_shape_handler(); initialize_fades(); initialize_images_manager(); load_environment_from_preferences(); initialize_game_state(); }
void init_opengl(Game *game) { //OpenGL initialization glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); //Set 2D mode (no perspective) glOrtho(0, WINDOW_WIDTH, (game->altitude - WINDOW_HEIGHT), game->altitude, -1, 1); //glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glDisable(GL_LIGHTING); //glDisable(GL_DEPTH_TEST); //glDisable(GL_FOG); //glDisable(GL_CULL_FACE); //Save the default modelview matrix glPushMatrix(); //Set the screen background color //glClearColor(0.1, 0.5, 1.0, 1.0); glClearColor(0.f, 0.f, 0.f, 1.f); glEnable(GL_TEXTURE_2D); initialize_fonts(); // //load the images file into a ppm structure // skyImage = ppm6GetImage("./images/Sunset.ppm"); characterImage = ppm6GetImage("./images/character2.ppm"); //create opengl texture elements glGenTextures(1, &skyTexture); glGenTextures(1, &characterTexture); glGenTextures(1, &silhouetteTexture); // //sky glBindTexture(GL_TEXTURE_2D, skyTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, skyImage->width, skyImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, skyImage->data); // /* //character glBindTexture(GL_TEXTURE_2D, characterTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, characterImage->width, characterImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, characterImage->data); // //character silhouette glBindTexture(GL_TEXTURE_2D, silhouetteTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); unsigned char *silhouetteData = buildAlphaData(characterImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, characterImage->width, characterImage->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData); delete [] silhouetteData; */ }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Set 2D mode (no perspective) glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); //Set the screen background color glClearColor(0.0, 0.0, 0.0, 1.0); //Initialize Fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); //system convert system("convert ./images/city.png ./images/city.ppm"); system("convert ./images/street.jpg ./images/street.ppm"); system("convert ./images/stars.png ./images/stars.ppm"); system("convert ./images/civilian.jpg ./images/civilian.ppm"); system("convert ./images/gameover.png ./images/gameover.ppm"); system("convert ./images/mainmenu.png ./images/mainmenu.ppm"); system("convert ./images/dcity.png ./images/dcity.ppm"); system("convert ./images/emissile.png ./images/emissile.ppm"); system("convert ./images/dmissile.png ./images/dmissile.ppm"); system("convert ./images/ufo.png ./images/ufo.ppm"); system("convert ./images/c_city.png ./images/c_city.ppm"); system("convert ./images/c_emissile.png ./images/c_emissile.ppm"); system("convert ./images/c_dmissile.png ./images/c_dmissile.ppm"); system("convert ./images/c_floor.png ./images/c_floor.ppm"); system("convert ./images/howtoplay.png ./images/howtoplay.ppm"); //system("convert ./images/c_bomber.png ./images/c_bomber.ppm"); //system("convert ./images/c_satellite.png ./images/c_satellite.ppm"); //system("convert ./images/c_silo.png ./images/c_silo.ppm"); //system("convert ./images/c_sbomb.png ./images/c_sbomb.ppm"); //load images into a ppm structure cityImage = ppm6GetImage("./images/city.ppm"); starsImage = ppm6GetImage("./images/stars.ppm"); streetImage = ppm6GetImage("./images/street.ppm"); civilianImage = ppm6GetImage("./images/civilian.ppm"); gameoverImage =ppm6GetImage("./images/gameover.ppm"); mainmenuImage = ppm6GetImage("./images/mainmenu.ppm"); dcityImage = ppm6GetImage("./images/dcity.ppm"); emissileImage = ppm6GetImage("./images/emissile.ppm"); dmissileImage = ppm6GetImage("./images/dmissile.ppm"); ufoImage = ppm6GetImage("./images/ufo.ppm"); howtoImage = ppm6GetImage("./images/howtoplay.ppm"); //classic images c_cityImage = ppm6GetImage("./images/c_city.ppm"); c_emissileImage = ppm6GetImage("./images/c_emissile.ppm"); c_dmissileImage = ppm6GetImage("./images/c_dmissile.ppm"); c_floorImage = ppm6GetImage("./images/c_floor.ppm"); //create opengl texture elements //stars starsTexture = makeTexture(starsTexture, starsImage); //street streetTexture = makeTexture(streetTexture, streetImage); //city cityTexture = makeTransparentTexture(cityTexture, cityImage); //civilian civilianTexture = makeTransparentTexture(civilianTexture, civilianImage); //dcity dcityTexture = makeTransparentTexture(cityTexture, dcityImage); //emissile emissileTexture = makeTransparentTexture(cityTexture, emissileImage); //dmissile dmissileTexture = makeTransparentTexture(cityTexture, dmissileImage); //ufo ufoTexture = makeTransparentTexture(cityTexture, ufoImage); //Others gameoverTexture = makeTransparentTexture(gameoverTexture, gameoverImage); mainmenuTexture = makeTexture(mainmenuTexture, mainmenuImage); howtoplayTexture = makeTexture(howtoplayTexture, howtoImage); //Classic c_floorTexture = makeTexture(c_floorTexture, c_floorImage); c_cityTexture = makeTransparentTexture(c_cityTexture, c_cityImage); c_emissileTexture = makeTransparentTexture(c_emissileTexture, c_emissileImage); c_dmissileTexture = makeTransparentTexture(c_dmissileTexture, c_dmissileImage); //remove ppm's remove("./images/city.ppm"); remove("./images/stars.ppm"); remove("./images/street.ppm"); remove("./images/civilian.ppm"); remove("./images/gameover.ppm"); remove("./images/mainmenu.ppm"); remove("./images/dcity.ppm"); remove("./images/emissile.ppm"); remove("./images/dmissile.ppm"); remove("./images/ufo.ppm"); remove("./images/howtoplay.ppm"); //remove classic stuff remove("./images/c_city.ppm"); remove("./images/c_emissile.ppm"); remove("./images/c_dmissile.ppm"); remove("./images/c_floor.ppm"); }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, xres, yres); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //This sets 2D mode (no perspective) glOrtho(0, xres, 0, yres, -1, 1); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); // //Clear the screen to black glClearColor(0.0, 0.0, 0.0, 1.0); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); system("convert ./images/titlescreen.png ./images/titlescreen.ppm"); system("convert ./images/bomb.png ./images/bomb.ppm"); system("convert ./images/game_over.png ./images/game_over.ppm"); system("convert ./images/ninja_robot.png ./images/ninja_robot.ppm"); system("convert ./images/ninja_robot2.png ./images/ninja_robot2.ppm"); system("convert ./images/help_menu.png ./images/help_menu.ppm"); system("convert ./images/explode.png ./images/explode.ppm"); system("convert ./images/paused.png ./images/paused.ppm"); system("convert ./images/portal0.png ./images/portal0.ppm"); system("convert ./images/portal1.png ./images/portal1.ppm"); //Load bomb image(s): bombImage = loadImage(BOMB_IMAGE_PATH.c_str()); bombTexture = generateTransparentTexture(bombTexture, bombImage); explodeImage = loadImage(EXPLODE_IMAGE_PATH.c_str()); explodeTexture = generateTransparentTexture(explodeTexture, explodeImage); //Load Portal images portalImage0 = loadImage(PORTAL_TYPE_0_PATH.c_str()); portalTexture0 = generateTransparentTexture(portalTexture0, portalImage0); portalImage1 = loadImage(PORTAL_TYPE_1_PATH.c_str()); portalTexture1 = generateTransparentTexture(portalTexture1, portalImage1); //Create background texture elements introBG = loadImage(BG_IMAGE_PATH.c_str()); introTexture = generateTexture(introTexture, introBG); bgImage1 = loadImage(BG_IMAGE_PATH1.c_str()); bgTexture = generateTexture(bgTexture, bgImage1); bgTexture1 = generateTexture(bgTexture1, bgImage1); bgImage2 = loadImage(BG_IMAGE_PATH2.c_str()); bgTexture2 = generateTexture(bgTexture2, bgImage2); //Create gameover texture: gameOverImage = loadImage(GAMEOVER_IMAGE_PATH.c_str()); gameOverTexture = generateTexture(gameOverTexture, gameOverImage); //Create help menu texture: helpMenuImage = loadImage(HELP_MENU_IMAGE_PATH.c_str()); helpMenuTexture = generateTexture(helpMenuTexture, helpMenuImage); //Create paused texture: pausedImage = loadImage(PAUSED_IMAGE_PATH.c_str()); pausedTexture = generateTransparentTexture(pausedTexture, pausedImage); //REMOVE PPMS: remove("./images/titlescreen.ppm"); remove("./images/bomb.ppm"); remove("./images/game_over.ppm"); remove("./images/ninja_robot.ppm"); remove("./images/ninja_robot2.ppm"); remove("./images/help_menu.ppm"); remove("./images/explode.ppm"); remove("./images/paused.ppm"); remove("./images/portal0.ppm"); remove("./images/portal1.ppm"); }
/** * Initializes the required resources. * * Should only be called once, right after starting. */ Code initialize(Window **window, Renderer **renderer) { char log_buffer[MAXIMUM_STRING_SIZE]; Uint32 renderer_flags = 0; initialize_logger(); initialize_profiler(); initialize_settings(); if (SDL_Init(SDL_INIT_FLAGS)) { sprintf(log_buffer, "SDL initialization error: %s.", SDL_GetError()); log_message(log_buffer); return CODE_ERROR; } SDL_ShowCursor(SDL_DISABLE); initialize_joystick(); if (!TTF_WasInit()) { if (TTF_Init()) { sprintf(log_buffer, "TTF initialization error: %s.", SDL_GetError()); log_message(log_buffer); return CODE_ERROR; } } if ((IMG_Init(IMG_FLAGS) & IMG_FLAGS) != IMG_FLAGS) { sprintf(log_buffer, "Failed to initialize required image support."); log_message(log_buffer); return CODE_ERROR; } /** * The number of columns and the number of lines are fixed. However, the * number of pixels we need for the screen is not. We find this number by * experimenting before creating the window. */ /* Log the size of the window we are going to create. */ *window = create_window(&window_width, &window_height); sprintf(log_buffer, "Created a %dx%d window.", window_width, window_height); log_message(log_buffer); if (*window == NULL) { sprintf(log_buffer, "SDL initialization error: %s.", SDL_GetError()); log_message(log_buffer); return CODE_ERROR; } if (initialize_fonts()) { sprintf(log_buffer, "Failed to initialize fonts."); log_message(log_buffer); return CODE_ERROR; } if (initialize_font_metrics()) { sprintf(log_buffer, "Failed to initialize font metrics."); log_message(log_buffer); return CODE_ERROR; } /* Must disable text input to prevent a name capture bug. */ SDL_StopTextInput(); set_window_title_and_icon(*window); if (get_renderer_type() == RENDERER_HARDWARE) { renderer_flags = SDL_RENDERER_ACCELERATED; } else { renderer_flags = SDL_RENDERER_SOFTWARE; } *renderer = SDL_CreateRenderer(*window, -1, renderer_flags); set_color(*renderer, COLOR_DEFAULT_BACKGROUND); clear(*renderer); return CODE_OK; }
SubtitleRenderer:: SubtitleRenderer(int display, int layer, const std::string& font_path, const std::string& italic_font_path, float font_size, float margin_left, float margin_bottom, bool centered, unsigned int white_level, unsigned int box_opacity, unsigned int lines) : prepared_(), dispman_element_(), dispman_display_(), display_(), context_(), surface_(), vg_font_(), vg_font_border_(), ft_library_(), ft_face_(), ft_face_italic_(), ft_stroker_(), line_height_(), box_offset_(), box_h_padding_(), margin_left_(), margin_bottom_(), buffer_width_(), buffer_height_(), centered_(centered), white_level_(white_level), box_opacity_(box_opacity) { try { uint32_t screen_width, screen_height; ENFORCE(graphics_get_display_size(display, &screen_width, &screen_height) >= 0); initialize_fonts(font_path, italic_font_path, font_size*screen_height); int abs_margin_bottom = static_cast<int>(margin_bottom * screen_height + 0.5f) - box_offset_; int buffer_padding = (line_height_+2)/4; int buffer_bottom = clamp(abs_margin_bottom + box_offset_ - buffer_padding, 0, (int) screen_height-1); int buffer_top = clamp(buffer_bottom + line_height_ * (int) lines + buffer_padding*2, 0, (int) screen_height-1); buffer_width_ = screen_width; buffer_height_ = buffer_top - buffer_bottom + 1; margin_left_ = (screen_width - screen_height) / 2 + static_cast<int>(margin_left * screen_height + 0.5f); margin_bottom_ = abs_margin_bottom - buffer_bottom; initialize_window(display, layer, 0, screen_height - buffer_top - 1, screen_width, buffer_height_); initialize_vg(); } catch (...) { destroy(); throw; } }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, xres, yres); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //This sets 2D mode (no perspective) glOrtho(0, xres, 0, yres, -1, 1); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); //Clear the screen glClearColor(1.0, 1.0, 1.0, 1.0); //glClear(GL_COLOR_BUFFER_BIT); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); // //load the images file into a ppm structure. // bigfootImage = ppm6GetImage("./images/bigfoot.ppm"); forestImage = ppm6GetImage("./images/forest.ppm"); forestTransImage = ppm6GetImage("./images/forestTrans.ppm"); umbrellaImage = ppm6GetImage("./images/umbrella.ppm"); // //create opengl texture elements glGenTextures(1, &bigfootTexture); glGenTextures(1, &silhouetteTexture); glGenTextures(1, &forestTexture); glGenTextures(1, &umbrellaTexture); //------------------------------------------------------------------------- //bigfoot // int w = bigfootImage->width; int h = bigfootImage->height; // glBindTexture(GL_TEXTURE_2D, bigfootTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, bigfootImage->data); //------------------------------------------------------------------------- // //silhouette //this is similar to a sprite graphic // glBindTexture(GL_TEXTURE_2D, silhouetteTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... unsigned char *silhouetteData = buildAlphaData(bigfootImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData); free(silhouetteData); //glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, // GL_RGB, GL_UNSIGNED_BYTE, bigfootImage->data); //------------------------------------------------------------------------- // //umbrella // glBindTexture(GL_TEXTURE_2D, umbrellaTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... silhouetteData = buildAlphaData(umbrellaImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, silhouetteData); free(silhouetteData); //glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, // GL_RGB, GL_UNSIGNED_BYTE, bigfootImage->data); //------------------------------------------------------------------------- // //forest glBindTexture(GL_TEXTURE_2D, forestTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, forestImage->width, forestImage->height, 0, GL_RGB, GL_UNSIGNED_BYTE, forestImage->data); //------------------------------------------------------------------------- // //forest transparent part // glBindTexture(GL_TEXTURE_2D, forestTransTexture); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // //must build a new set of data... w = forestTransImage->width; h = forestTransImage->height; unsigned char *ftData = buildAlphaData(forestTransImage); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ftData); free(ftData); //glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, //GL_RGB, GL_UNSIGNED_BYTE, bigfootImage->data); //------------------------------------------------------------------------- }