void rect(const char* binding, pp::Vec2d pos, pp::Vec2d size ) { GLuint texobj; if ( !get_texture_binding( binding, &texobj ) ) { texobj = 0; } glPushMatrix(); { glBindTexture( GL_TEXTURE_2D, texobj ); glEnable( GL_TEXTURE_2D ); glColor4f( 1.0, 1.0, 1.0, 1.0 ); glTranslatef( pos.x, pos.y, 0.0 ); glBegin( GL_QUADS ); { glTexCoord2f( 0.0, 0.0 ); glVertex2f( 0.0, 0.0 ); glTexCoord2f( 1.0, 0.0 ); glVertex2f( size.x, 0.0 ); glTexCoord2f( 1.0, 1.0 ); glVertex2f( size.x, size.y ); glTexCoord2f( 0.0, 1.0 ); glVertex2f( 0.0, size.y ); } glEnd(); } glPopMatrix(); }
void draw_ui_snow( void ) { GLuint texture_id; char *binding; pp::Vec2d *pt, *tex_min, *tex_max; double size; double xres, yres; int i; xres = getparam_x_resolution(); yres = getparam_y_resolution(); UIMgr.setupDisplay(); binding = "ui_snow_particle"; if (!get_texture_binding( "ui_snow_particle", &texture_id ) ) { print_warning( IMPORTANT_WARNING, "Couldn't get texture for binding %s", binding ); texture_id = 0; } glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glBindTexture( GL_TEXTURE_2D, texture_id ); glColor4f( particleColor[0], particleColor[1], particleColor[2], particleColor[3] ); glPushMatrix(); { for ( i=0; i<num_particles; i++) { pt = &particles[i].pt; size = particles[i].size; tex_min = &particles[i].tex_min; tex_max = &particles[i].tex_max; glPushMatrix(); { glTranslatef( pt->x*xres, pt->y*yres, 0 ); glBegin( GL_QUADS ); { glTexCoord2f( tex_min->x, tex_min->y ); glVertex2f( 0, 0 ); glTexCoord2f( tex_max->x, tex_min->y ); glVertex2f( size, 0 ); glTexCoord2f( tex_max->x, tex_max->y ); glVertex2f( size, size ); glTexCoord2f( tex_min->x, tex_max->y ); glVertex2f( 0, size ); } glEnd(); } glPopMatrix(); } } glPopMatrix(); }
/*! Sets the widget positions and draws other on-screen goo \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ static void draw_preview() { GLuint texobj; { rect_t screen_rect; open_course_data_t *data; int w=getparam_x_resolution(); int h=getparam_y_resolution(); float colors[]={1, 1, 1, 1}; shader_set_color(colors); data = (open_course_data_t*) get_list_elem_data( cur_elem ); if ( !get_texture_binding( data->course, &texobj ) ) { if ( !get_texture_binding( "no_preview", &texobj ) ) { texobj = 0; } } glBindTexture( GL_TEXTURE_2D, texobj ); draw_textured_quad(0.105*w, 0.45*h, 0.34*w, 0.34*h); } }
void draw_sponsor_loading() { GLuint texobj; int w = getparam_x_resolution(); int h = getparam_y_resolution(); glEnable( GL_TEXTURE_2D ); /* loading */ if ( get_texture_binding( sponsor_selected, &texobj ) ) { glBindTexture( GL_TEXTURE_2D, texobj ); draw_quad(0,0, w, h ); } }
void UIManager::drawCursor() { GLuint texobj; char *binding; binding = "mouse_cursor"; if ( !get_texture_binding( binding, &texobj ) ) { texobj = 0; } setupDisplay(); glBindTexture( GL_TEXTURE_2D, texobj ); glBegin( GL_QUADS ); { glTexCoord2f( 0, 1 ); glVertex2f( cursorPos.x, cursorPos.y ); glTexCoord2f( 0, 0 ); glVertex2f( cursorPos.x, cursorPos.y - 32 ); glTexCoord2f( 1, 0 ); glVertex2f( cursorPos.x + 32, cursorPos.y - 32 ); glTexCoord2f( 1, 1 ); glVertex2f( cursorPos.x + 32, cursorPos.y ); } glEnd(); }
void draw_ui_snow( void ) { GLuint texture_id; char *binding; point2d_t *pt, *tex_min, *tex_max; scalar_t size; scalar_t xres, yres; int i; xres = getparam_x_resolution(); yres = getparam_y_resolution(); ui_setup_display(); binding = "snow_particle"; if (!get_texture_binding( "snow_particle", &texture_id ) ) { print_warning( IMPORTANT_WARNING, "Couldn't get texture for binding %s", binding ); texture_id = 0; } glBindTexture( GL_TEXTURE_2D, texture_id ); shader_set_color(particle_colour); { GLfloat* vertices=(GLfloat*)malloc(8*num_particles*sizeof(GLfloat)); GLfloat* tex_coords=(GLfloat*)malloc(8*num_particles*sizeof(GLfloat)); GLushort* indices=(GLushort*)malloc(6*num_particles*sizeof(GLushort)); for ( i=0; i<num_particles; i++) { init_arrays_for_particle(particles[i], vertices+i*8, tex_coords+i*8); int firstvert=i*4; int firstindex=i*6; indices[0+firstindex]=0+firstvert; indices[1+firstindex]=1+firstvert; indices[2+firstindex]=2+firstvert; indices[3+firstindex]=2+firstvert; indices[4+firstindex]=3+firstvert; indices[5+firstindex]=0+firstvert; } //print_debug(DEBUG_OTHER, "indices %d %d %d %d %d %d %d %d %d %d %d %d", indices[0], indices[1], indices[2], indices[3], indices[4], indices[5], indices[6], indices[7], indices[8], indices[9], indices[10], indices[11]); //print_debug(DEBUG_OTHER, "vertices %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5], vertices[6], vertices[7], vertices[8], vertices[9], vertices[10], vertices[11], vertices[12], vertices[13], vertices[14], vertices[15]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glVertexAttribPointer(shader_get_attrib_location(SHADER_VERTEX_NAME), 2, GL_FLOAT, GL_FALSE, 0, vertices); glEnableVertexAttribArray(shader_get_attrib_location(SHADER_VERTEX_NAME)); glVertexAttribPointer(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME), 2, GL_FLOAT, GL_FALSE, 0, tex_coords); glEnableVertexAttribArray(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME)); glDrawElements(GL_TRIANGLES, num_particles*6, GL_UNSIGNED_SHORT, indices); glVertexAttribPointer(shader_get_attrib_location(SHADER_VERTEX_NAME), 2, GL_FLOAT, GL_FALSE, 0, 0); glDisableVertexAttribArray(shader_get_attrib_location(SHADER_VERTEX_NAME)); glVertexAttribPointer(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME), 2, GL_FLOAT, GL_FALSE, 0, 0); glDisableVertexAttribArray(shader_get_attrib_location(SHADER_TEXTURE_COORD_NAME)); free(vertices); free(tex_coords); } }
/*! Draws the mouse cursor \author jfpatry \date Created: 2000-09-29 \date Modified: 2000-09-29 */ static void ui_draw_cursor( void ) { GLuint texobj; char *binding; binding = "mouse_cursor"; if ( !get_texture_binding( binding, &texobj ) ) { texobj = 0; } ui_setup_display(); glBindTexture( GL_TEXTURE_2D, texobj ); #ifdef __APPLE__DISABLED__ const GLfloat vertices []= { cursor_pos.x, cursor_pos.y, cursor_pos.x, cursor_pos.y - CURSOR_TEX_SIZE, cursor_pos.x + CURSOR_TEX_SIZE, cursor_pos.y - CURSOR_TEX_SIZE, cursor_pos.x + CURSOR_TEX_SIZE, cursor_pos.y }; const GLfloat texCoords []= { 0,1, 0,0, 1,0, 1,1 }; glEnableClientState (GL_VERTEX_ARRAY); glVertexPointer (2, GL_FLOAT , 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); #else glBegin( GL_QUADS ); { glTexCoord2f( 0, 1 ); glVertex2f( cursor_pos.x, cursor_pos.y ); glTexCoord2f( 0, 0 ); glVertex2f( cursor_pos.x, cursor_pos.y - CURSOR_TEX_SIZE ); glTexCoord2f( 1, 0 ); glVertex2f( cursor_pos.x + CURSOR_TEX_SIZE, cursor_pos.y - CURSOR_TEX_SIZE ); glTexCoord2f( 1, 1 ); glVertex2f( cursor_pos.x + CURSOR_TEX_SIZE, cursor_pos.y ); } glEnd(); #endif }
static void set_widget_positions_and_draw_decorations() { int h = getparam_y_resolution(); int box_width, box_height, box_max_y; int x_org, y_org; char *string; font_t *font; int text_width, asc, desc; list_t cup_list; GLuint texobj; #ifdef __APPLE__ /* set the dimensions of the box in which all widgets should fit */ box_width = 300; box_height = 310; box_max_y = h - 128; x_org = 10; y_org = h/2 - box_height/2; if ( y_org + box_height > box_max_y ) { y_org = box_max_y - box_height; } button_set_position( back_btn, make_point2d( x_org + 40 - button_get_width( back_btn )/2.0, 12 ) ); button_set_position( continue_btn, make_point2d( x_org + 232 - button_get_width( continue_btn )/2.0, 12 ) ); button_set_position( howToPlay_btn, make_point2d( x_org + 160 - button_get_width( continue_btn )/2.0, 100 ) ); //Out of the field of view //in Tux Rider World Challenge, there is no more events and cup, just training //I'm adapting from The Tux Racer system by selecting the first and only event //I hide its list box out of the field of view //and each cup for this event is a training listbox_set_position( event_listbox, make_point2d( x_org+500, y_org + 500 ) ); listbox_set_position( cup_listbox, make_point2d( x_org+50, y_org + 193 ) ); #else int w = getparam_x_resolution(); /* set the dimensions of the box in which all widgets should fit */ box_width = 460; box_height = 310; box_max_y = h - 128; x_org = w/2 - box_width/2; y_org = h/2 - box_height/2; if ( y_org + box_height > box_max_y ) { y_org = box_max_y - box_height; } button_set_position( back_btn, make_point2d( x_org + 131 - button_get_width( back_btn )/2.0, 42 ) ); button_set_position( continue_btn, make_point2d( x_org + 329 - button_get_width( continue_btn )/2.0, 42 ) ); listbox_set_position( cup_listbox, make_point2d( x_org + 52, y_org + 103 ) ); listbox_set_position( event_listbox, make_point2d( x_org + 52, y_org + 193 ) ); #endif /* * Draw other stuff */ /* Event & cup icons */ if ( !get_texture_binding( get_event_icon_texture_binding( event_data ), &texobj ) ) { texobj = 0; } glBindTexture( GL_TEXTURE_2D, texobj ); glBegin( GL_QUADS ); { point2d_t tll, tur; point2d_t ll, ur; #ifdef __APPLE__ //out of the field of view ll = make_point2d( x_org, y_org + 500 ); ur = make_point2d( x_org + 44, y_org + 500 + 44 ); tll = make_point2d( 0, 0 ); tur = make_point2d( 44.0/64.0, 44.0/64.0 ); #else ll = make_point2d( x_org, y_org + 193 ); ur = make_point2d( x_org + 44, y_org + 193 + 44 ); tll = make_point2d( 0, 0 ); tur = make_point2d( 44.0/64.0, 44.0/64.0 ); #endif glTexCoord2f( tll.x, tll.y ); glVertex2f( ll.x, ll.y ); glTexCoord2f( tur.x, tll.y ); glVertex2f( ur.x, ll.y ); glTexCoord2f( tur.x, tur.y ); glVertex2f( ur.x, ur.y ); glTexCoord2f( tll.x, tur.y ); glVertex2f( ll.x, ur.y ); } glEnd(); if ( !get_texture_binding( get_cup_icon_texture_binding( (cup_data_t*) get_list_elem_data( cur_cup ) ), &texobj ) ) { texobj = 0; } glBindTexture( GL_TEXTURE_2D, texobj ); #ifdef __APPLE__DISABLED__ { point2d_t tll, tur; point2d_t ll, ur; ll = make_point2d( x_org, y_org + 103 ); ur = make_point2d( x_org + 44, y_org + 103 + 44 ); tll = make_point2d( 0, 0 ); tur = make_point2d( 44.0/64.0, 44.0/64.0 ); const GLfloat vertices []= { ll.x, ll.y, ur.x, ll.y, ur.x, ur.y, ll.x, ur.y }; const GLfloat texCoords []= { tll.x, tll.y, tur.x, tll.y, tur.x, tur.y, tll.x, tur.y, }; glEnableClientState (GL_VERTEX_ARRAY); glVertexPointer (2, GL_FLOAT , 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } #else glBegin( GL_QUADS ); { point2d_t tll, tur; point2d_t ll, ur; #ifdef __APPLE__ ll = make_point2d( x_org, y_org + 193 ); ur = make_point2d( x_org + 44, y_org + 193 + 44 ); tll = make_point2d( 0, 0 ); tur = make_point2d( 44.0/64.0, 44.0/64.0 ); #else ll = make_point2d( x_org, y_org + 103 ); ur = make_point2d( x_org + 44, y_org + 103 + 44 ); tll = make_point2d( 0, 0 ); tur = make_point2d( 44.0/64.0, 44.0/64.0 ); #endif glTexCoord2f( tll.x, tll.y ); glVertex2f( ll.x, ll.y ); glTexCoord2f( tur.x, tll.y ); glVertex2f( ur.x, ll.y ); glTexCoord2f( tur.x, tur.y ); glVertex2f( ur.x, ur.y ); glTexCoord2f( tll.x, tur.y ); glVertex2f( ll.x, ur.y ); } glEnd(); #endif if ( !get_font_binding( "menu_label", &font ) ) { print_warning( IMPORTANT_WARNING, "Couldn't get font for binding menu_label" ); } else { bind_font_texture( font ); #ifdef __APPLE__ string = "Select a training"; #else string = "Select event and cup"; #endif get_font_metrics( font, string, &text_width, &asc, &desc ); glPushMatrix(); { glTranslatef( x_org + box_width/2.0 - text_width/2.0, y_org + 310 - asc, 0 ); draw_string( font, string ); } glPopMatrix(); } if ( !get_font_binding( "event_and_cup_label", &font ) ) { print_warning( IMPORTANT_WARNING, "Couldn't get font for binding menu_label" ); } #ifdef __APPLE__ cur_event = listbox_get_current_item( event_listbox ); event_data = (event_data_t*) get_list_elem_data( cur_event ); cup_list = get_event_cup_list( event_data ); cur_cup = listbox_get_current_item( cup_listbox ); if ( is_cup_complete( event_data, cur_cup ) ) { string = "You've won this Training !"; } else if ( is_cup_first_incomplete_cup( event_data, cur_cup ) ) { string = "You must complete this training first"; } else { string = "You cannot enter this training yet"; } if ( !get_font_binding( "cup_status", &font ) ) { print_warning( IMPORTANT_WARNING, "Couldn't get font for binding cup_status" ); } else { bind_font_texture( font ); get_font_metrics( font, string, &text_width, &asc, &desc ); glPushMatrix(); { glTranslatef( x_org + box_width/2.0 - text_width/2.0, y_org+140, 0 ); draw_string( font, string ); } glPopMatrix(); } #else else {
/*! Draws a button widget \return None \author jfpatry \date Created: 2000-09-18 \date Modified: 2000-09-18 */ void button_draw( button_t *button ) { GLuint texobj; texture_region_t *tex; point2d_t pos; scalar_t w, h; char *font_binding; check_assertion( button != NULL, "button is NULL" ); pos = button->pos; w = button->w; h = button->h; glEnable( GL_TEXTURE_2D ); tex = NULL; font_binding = NULL; if ( !button->enabled ) { if ( button->disabled_tex.binding ) { tex = &button->disabled_tex; } else if ( button->tex.binding ) { tex = &button->tex; } if ( button->disabled_font_binding ) { font_binding = button->disabled_font_binding; } else if ( button->font_binding ) { font_binding = button->font_binding; } } else if ( button->clicked ) { if ( button->clicked_tex.binding ) { tex = &button->clicked_tex; } else if ( button->hilit_tex.binding ) { tex = &button->hilit_tex; } else if ( button->tex.binding ) { tex = &button->tex; } if ( button->hilit_font_binding ) { font_binding = button->hilit_font_binding; } else if ( button->font_binding ) { font_binding = button->font_binding; } } else if ( button->focused ) { if ( button->hilit_tex.binding ) { tex = &button->hilit_tex; } else if ( button->tex.binding ) { tex = &button->tex; } if ( button->hilit_font_binding ) { font_binding = button->hilit_font_binding; } else if ( button->font_binding ) { font_binding = button->font_binding; } } else { if ( button->tex.binding ) { tex = &button->tex; } if ( button->font_binding ) { font_binding = button->font_binding; } } if ( tex != NULL ) { if ( !get_texture_binding( tex->binding, &texobj ) ) { print_warning( IMPORTANT_WARNING, "Couldnt get texture object for binding %s", tex->binding ); texobj = 0; } glBindTexture( GL_TEXTURE_2D, texobj ); glColor4dv( (scalar_t*) &tex->colour ); glBegin( GL_QUADS ); { glTexCoord2f( tex->ll.x, tex->ll.y ); glVertex3f( pos.x, pos.y, 0 ); glTexCoord2f( tex->ur.x, tex->ll.y ); glVertex3f( pos.x + w, pos.y, 0 ); glTexCoord2f( tex->ur.x, tex->ur.y ); glVertex3f( pos.x + w, pos.y + h, 0 ); glTexCoord2f( tex->ll.x, tex->ur.y ); glVertex3f( pos.x, pos.y + h, 0 ); } glEnd(); } if ( font_binding && button->label != NULL ) { font_t *font; int w, asc, desc; if (!get_font_binding( font_binding, &font )) { print_warning( IMPORTANT_WARNING, "Couldn't get font object for binding %s", font_binding ); font = NULL; } else { bind_font_texture( font ); get_font_metrics( font, button->label, &w, &asc, &desc ); glPushMatrix(); { glTranslatef( button->pos.x + button->w/2.0 - w/2.0, button->pos.y + button->h/2.0 - asc/2.0 + desc/2.0, 0.0 ); draw_string( font, button->label ); } glPopMatrix(); } } }
void draw_trees() { tree_t *treeLocs; int numTrees; scalar_t treeRadius; scalar_t treeHeight; int i; GLuint texture_id = 0; vector_t normal; scalar_t fwd_clip_limit, bwd_clip_limit, fwd_tree_detail_limit; int tree_type = -1; char *tree_name = 0; scalar_t itemRadius; scalar_t itemHeight; int item_type = -1; char * item_name = 0; item_type_t *item_types; treeLocs = treeLocsOrderedByZ; numTrees = get_num_trees(); item_types = get_item_types(); fwd_clip_limit = getparam_forward_clip_distance(); bwd_clip_limit = getparam_backward_clip_distance(); fwd_tree_detail_limit = getparam_tree_detail_distance(); set_gl_options( TREES ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); set_material( white, black, 1.0 ); #ifdef __APPLE__ #undef glVertexPointer #undef glTexCoordPointer #undef glEnableClientState #undef glDisableClientState #undef glDrawArrays static const GLfloat verticesTree []= { -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 1.0, 1.0, }; static const GLfloat texCoordsTree []= { 0.0, 0.0 , 1.0, 0.0 , 1.0, 1.0 , 0.0, 1.0 , 0.0, 0.0 , 1.0, 1.0 , 0.0, 0.0 , 1.0, 0.0 , 1.0, 1.0 , 0.0, 1.0 , 0.0, 0.0 , 1.0, 1.0 , }; glVertexPointer (3, GL_FLOAT , 0, verticesTree); glTexCoordPointer(2, GL_FLOAT, 0, texCoordsTree); glEnableClientState(GL_TEXTURE_COORD_ARRAY); #endif for (i = first_tree_to_check; i< numTrees; i++ ) { if ( clip_course ) { if ( eye_pt.z - treeLocs[i].ray.pt.z > fwd_clip_limit ) //printf("break : eye_pt.z - treeLocs[i].ray.pt.z = %f > fwd_clip_limit = %f\n",eye_pt.z - treeLocs[i].ray.pt.z,fwd_clip_limit); break; if ( treeLocs[i].ray.pt.z - eye_pt.z > bwd_clip_limit ){ first_tree_to_check = i; //printf("continue : treeLocs[i].ray.pt.z - eye_pt.z = %f > bwd_clip_limit = %f\n",treeLocs[i].ray.pt.z - eye_pt.z,bwd_clip_limit); continue; } //printf("condition 1 : eye_pt.z - treeLocs[i].ray.pt.z = %f > fwd_clip_limit = %f\n",eye_pt.z - treeLocs[i].ray.pt.z,fwd_clip_limit); // printf("condition 2 : treeLocs[i].ray.pt.z - eye_pt.z = %f > bwd_clip_limit = %f\n",treeLocs[i].ray.pt.z - eye_pt.z,bwd_clip_limit); } /* verify that the correct texture is bound */ if (treeLocs[i].tree_type != tree_type) { tree_type = treeLocs[i].tree_type; tree_name = get_tree_name(tree_type); if (!get_texture_binding( tree_name, &texture_id ) ) { texture_id = 0; } glBindTexture( GL_TEXTURE_2D, texture_id ); } glPushMatrix(); glTranslatef( treeLocs[i].ray.pt.x, treeLocs[i].ray.pt.y, treeLocs[i].ray.pt.z ); treeRadius = treeLocs[i].diam/2.; treeHeight = treeLocs[i].height; normal = subtract_points( eye_pt, treeLocs[i].ray.pt ); normalize_vector( &normal ); glNormal3f( normal.x, normal.y, normal.z ); #ifdef __APPLE__ glScalef(treeRadius, treeHeight, treeRadius); bool drawTwoPlanes = false; if ( !clip_course || eye_pt.z - treeLocs[i].ray.pt.z < fwd_tree_detail_limit ) drawTwoPlanes = true; glDrawArrays(GL_TRIANGLES, 0, 6 + drawTwoPlanes ? 6 : 0); #else glBegin( GL_QUADS ); glTexCoord2f( 0., 0. ); glVertex3f( -treeRadius, 0.0, 0.0 ); glTexCoord2f( 1., 0. ); glVertex3f( treeRadius, 0.0, 0.0 ); glTexCoord2f( 1., 1. ); glVertex3f( treeRadius, treeHeight, 0.0 ); glTexCoord2f( 0., 1. ); glVertex3f( -treeRadius, treeHeight, 0.0 ); if ( !clip_course || eye_pt.z - treeLocs[i].ray.pt.z < fwd_tree_detail_limit ) { glTexCoord2f( 0., 0. ); glVertex3f( 0.0, 0.0, -treeRadius ); glTexCoord2f( 1., 0. ); glVertex3f( 0.0, 0.0, treeRadius ); glTexCoord2f( 1., 1. ); glVertex3f( 0.0, treeHeight, treeRadius ); glTexCoord2f( 0., 1. ); glVertex3f( 0.0, treeHeight, -treeRadius ); } glEnd(); #endif glPopMatrix(); } #ifdef __APPLE__ static const GLfloat verticesItem []= { -1.0, 0.0, 1.0, 1.0, 0.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0, 1.0, -1.0, }; static const GLfloat texCoordsItem []= { 0.0, 0.0 , 1.0, 0.0 , 1.0, 1.0 , 0.0, 1.0 , 0.0, 0.0 , 1.0, 1.0 , }; glVertexPointer (3, GL_FLOAT , 0, verticesItem); glTexCoordPointer(2, GL_FLOAT, 0, texCoordsItem); #endif texture_id = 0; for (i = 0; i< numItems; i++ ) { #ifdef __APPLE__ if (g_game.is_speed_only_mode || !g_game.practicing) { if ( itemLocs[i].collectable == 1) { /* In speed mode or in tutorial we don't want to draw fishes*/ continue; } } #endif if ( itemLocs[i].collectable == 0 || itemLocs[i].drawable == False) { /* already collected or not to be drawn*/ continue; } if ( clip_course ) { if ( eye_pt.z - itemLocs[i].ray.pt.z > fwd_clip_limit ) continue; if ( itemLocs[i].ray.pt.z - eye_pt.z > bwd_clip_limit ) continue; } /* load texture id if needed */ if (!itemLocs[i].sponsor_binded) { itemLocs[i].sponsor_binded = True; if(itemLocs[i].item_type == kFlagType) { int r = rand() % 2; item_name = r ? "flag_furlan" : "flag_zag"; /*un drapeau sur 2 portera le logo zag ou furlan, au hasard*/ } else { item_name = get_item_name(itemLocs[i].item_type); } if (!get_texture_binding( item_name, &itemLocs[i].tid ) ) { itemLocs[i].tid = 0; } } /* verify that the correct texture is bound */ if (itemLocs[i].tid != texture_id) { glBindTexture( GL_TEXTURE_2D, itemLocs[i].tid ); texture_id = itemLocs[i].tid; } glPushMatrix(); { glTranslatef( itemLocs[i].ray.pt.x, itemLocs[i].ray.pt.y, itemLocs[i].ray.pt.z ); itemRadius = itemLocs[i].diam/2.; itemHeight = itemLocs[i].height; if ( item_types[item_type].use_normal ) { normal = item_types[item_type].normal; } else { normal = subtract_points( eye_pt, itemLocs[i].ray.pt ); normalize_vector( &normal ); } if (normal.y == 1.0) { continue; } glNormal3f( normal.x, normal.y, normal.z ); normal.y = 0.0; normalize_vector( &normal ); #ifdef __APPLE__ glScalef(itemRadius*normal.z, itemHeight, itemRadius*normal.x); glDrawArrays(GL_TRIANGLES, 0, 6); #else glBegin( GL_QUADS ); { glTexCoord2f( 0., 0. ); glVertex3f( -itemRadius*normal.z, 0.0, itemRadius*normal.x ); glTexCoord2f( 1., 0. ); glVertex3f( itemRadius*normal.z, 0.0, -itemRadius*normal.x ); glTexCoord2f( 1., 1. ); glVertex3f( itemRadius*normal.z, itemHeight, -itemRadius*normal.x ); glTexCoord2f( 0., 1. ); glVertex3f( -itemRadius*normal.z, itemHeight, itemRadius*normal.x ); } glEnd(); #endif } glPopMatrix(); } #ifdef __APPLE__ glDisableClientState(GL_TEXTURE_COORD_ARRAY); #endif }
void draw_sky(point_t pos) { GLuint texture_id[6]; set_gl_options( SKY ); if (!(get_texture_binding( "sky_front", &texture_id[0] ) && get_texture_binding( "sky_top", &texture_id[1] ) && get_texture_binding( "sky_bottom", &texture_id[2] ) && get_texture_binding( "sky_left", &texture_id[3] ) && get_texture_binding( "sky_right", &texture_id[4] ) && get_texture_binding( "sky_back", &texture_id[5] ) ) ) { return; } glColor4f( 1.0, 1.0, 1.0, 1.0 ); glPushMatrix(); glTranslatef(pos.x, pos.y, pos.z); #ifdef __APPLE__ #undef glEnableClientState #undef glDisableClientState #undef glVertexPointer #undef glTexCoordPointer #undef glDrawArrays #undef glDrawElements static const GLfloat vertices []= { -1, -1, -1, //0 1, -1, -1, //1 1, 1, -1, //2 -1, 1, -1, //3 -1, -1, -1, //0 1, 1, -1, //2 -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, }; static const GLfloat texCoords []= { // Work around an iphone FPU/GL? bug // that makes the plane and texture non contiguous. // this removes an artifacts visible in the sky #define ZERO 0.01 #define ONE 0.99 ZERO, ZERO , ONE, ZERO , ONE, ONE , ZERO, ONE , ZERO, ZERO , ONE, ONE , ZERO, ZERO , ONE, ZERO , ONE, ONE , ZERO, ONE , ZERO, ZERO , ONE, ONE , ZERO, ZERO , ONE, ZERO , ONE, ONE , ZERO, ONE , ZERO, ZERO , ONE, ONE , ZERO, ZERO , ONE, ZERO , ONE, ONE , ZERO, ONE , ZERO, ZERO , ONE, ONE , ZERO, ZERO , ONE, ZERO , ONE, ONE , ZERO, ONE , ZERO, ZERO , ONE, ONE , ZERO, ZERO , ONE, ZERO , ONE, ONE , ZERO, ONE , ZERO, ZERO , ONE, ONE , }; glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glVertexPointer (3, GL_FLOAT , 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); int i = 0; for(i =0; i < 6; i++) { glBindTexture( GL_TEXTURE_2D, texture_id[i] ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glDrawArrays(GL_TRIANGLES, i*6, 6); } #else glBindTexture( GL_TEXTURE_2D, texture_id[0] ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glBegin(GL_QUADS); glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1, -1, -1); glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1, -1, -1); glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1, 1, -1); glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1, 1, -1); glEnd(); glBindTexture( GL_TEXTURE_2D, texture_id[1] ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glBegin(GL_QUADS); glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1, 1, -1); glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1, 1, -1); glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1, 1, 1); glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1, 1, 1); glEnd(); glBindTexture( GL_TEXTURE_2D, texture_id[2] ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glBegin(GL_QUADS); glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1, -1, 1); glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1, -1, 1); glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1, -1, -1); glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1, -1, -1); glEnd(); glBindTexture( GL_TEXTURE_2D, texture_id[3] ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glBegin(GL_QUADS); glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1, -1, 1); glTexCoord2f( 1.0, 0.0 ); glVertex3f( -1, -1, -1); glTexCoord2f( 1.0, 1.0 ); glVertex3f( -1, 1, -1); glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1, 1, 1); glEnd(); glBindTexture( GL_TEXTURE_2D, texture_id[4] ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glBegin(GL_QUADS); glTexCoord2f( 0.0, 0.0 ); glVertex3f( 1, -1, -1); glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1, -1, 1); glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1, 1, 1); glTexCoord2f( 0.0, 1.0 ); glVertex3f( 1, 1, -1); glEnd(); glBindTexture( GL_TEXTURE_2D, texture_id[5] ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glBegin(GL_QUADS); glTexCoord2f( 0.0, 0.0 ); glVertex3f( 1, -1, 1); glTexCoord2f( 1.0, 0.0 ); glVertex3f( -1, -1, 1); glTexCoord2f( 1.0, 1.0 ); glVertex3f( -1, 1, 1); glTexCoord2f( 0.0, 1.0 ); glVertex3f( 1, 1, 1); glEnd(); #endif glPopMatrix(); }
/*! Sets the widget positions and draws other on-screen goo \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ static void set_widget_positions_and_draw_decorations() { int w = getparam_x_resolution(); int h = getparam_y_resolution(); int box_width, box_height, box_max_y; int x_org, y_org; char *string; font_t *font; char *current_course; int text_width, asc, desc; GLuint texobj; /* set the dimensions of the box in which all widgets should fit */ #ifdef __APPLE__ box_width = w; box_height = 200 * mHeight / 320; box_max_y = h - 128 * mHeight / 320; x_org = 10 * mHeight / 320; y_org = box_height/2 * mHeight / 320; if ( y_org + box_height > box_max_y ) { y_org = box_max_y - box_height + 50 * mHeight / 320; } button_set_position( back_btn, make_point2d( 0, 0 ) ); button_set_position( start_btn, make_point2d( box_width - button_get_width( start_btn ), 0 ) ); listbox_set_position( race_listbox, make_point2d( 160 * mHeight / 320, box_height/2.0+40 * mHeight / 320 ) ); #ifdef __APPLE__ textarea_set_position( desc_ta, make_point2d( 1000, 1000 ) ); #else textarea_set_position( desc_ta, make_point2d( x_org, y_org + 66 * mHeight / 320 ) ); #endif if ( g_game.practicing || ( cup_complete && conditions_ssbtn && wind_ssbtn && snow_ssbtn && mirror_ssbtn ) ) { ssbutton_set_position( conditions_ssbtn, make_point2d( x_org + box_width - 4*36 + 4, y_org + 151 ) ); ssbutton_set_position( wind_ssbtn, make_point2d( x_org + box_width - 3*36 + 4 , y_org + 151 ) ); ssbutton_set_position( snow_ssbtn, make_point2d( x_org + box_width - 2*36 + 4, y_org + 151 ) ); ssbutton_set_position( mirror_ssbtn, make_point2d( x_org + box_width - 1*36 + 4, y_org + 151 ) ); #else box_width = 460; box_height = 310; box_max_y = h - 128; x_org = w/2 - box_width/2; y_org = h/2 - box_height/2; if ( y_org + box_height > box_max_y ) { y_org = box_max_y - box_height; } button_set_position( back_btn, make_point2d( x_org + 131 - button_get_width( back_btn )/2.0, 42 ) ); button_set_position( start_btn, make_point2d( x_org + 343 - button_get_width( start_btn )/2.0, 42 ) ); listbox_set_position( race_listbox, make_point2d( x_org, y_org + 221 ) ); textarea_set_position( desc_ta, make_point2d( x_org, y_org + 66 ) ); if ( g_game.practicing || ( cup_complete && conditions_ssbtn && wind_ssbtn && snow_ssbtn && mirror_ssbtn ) ) { ssbutton_set_position( conditions_ssbtn, make_point2d( x_org + box_width - 4*36 + 4, y_org + 181 ) ); ssbutton_set_position( wind_ssbtn, make_point2d( x_org + box_width - 3*36 + 4 , y_org + 181 ) ); ssbutton_set_position( snow_ssbtn, make_point2d( x_org + box_width - 2*36 + 4, y_org + 181 ) ); ssbutton_set_position( mirror_ssbtn, make_point2d( x_org + box_width - 1*36 + 4, y_org + 181 ) ); #endif } else { /* Draw tux life icons */ GLuint texobj; int i; glPushMatrix(); { #ifdef __APPLE__ glTranslatef( 10 * mHeight / 320, 60 * mHeight / 320, 0 ); #else glTranslatef( x_org + box_width - 4*36 + 4, y_org + 181, 0 ); #endif check_assertion( INIT_NUM_LIVES == 4, "Assumption about number of lives invalid -- " "need to recode this part" ); if ( !get_texture_binding( "tux_life", &texobj ) ) { texobj = 0; } glBindTexture( GL_TEXTURE_2D, texobj ); for ( i=0; i<4; i++ ) { point2d_t ll, ur; if ( plyr->lives > i ) { ll = make_point2d( 0, 0.5 ); ur = make_point2d( 1, 1 ); } else { ll = make_point2d( 0, 0 ); ur = make_point2d( 1, 0.5 ); } glBegin( GL_QUADS ); { glTexCoord2f( ll.x, ll.y ); glVertex2f( 0, 0 ); glTexCoord2f( ur.x, ll.y ); glVertex2f( 32 * mHeight / 320, 0 ); glTexCoord2f( ur.x, ur.y ); glVertex2f( 32 * mHeight / 320, 32 * mHeight / 320 ); glTexCoord2f( ll.x, ur.y ); glVertex2f( 0, 32 * mHeight / 320 ); } glEnd(); glTranslatef( 36 * mHeight / 320, 0, 0 ); } } glPopMatrix(); } #ifndef __APPLE__ // We don't care about that stuff /* Draw other stuff */ if ( !get_font_binding( "menu_label", &font ) ) { print_warning( IMPORTANT_WARNING, "Couldn't get font for binding menu_label" ); } else { bind_font_texture( font ); string = "Select a race"; get_font_metrics( font, string, &text_width, &asc, &desc ); glPushMatrix(); { glTranslatef( x_org + box_width/2.0 - text_width/2.0, y_org + 310 - asc, 0 ); draw_string( font, string ); } glPopMatrix(); } /* Draw text indicating race requirements (if race not completed), or results in race if race completed. */ draw_status_msg( x_org, y_org, box_width, box_height ); #else /* Draw text indicating race requirements (if race not completed), or results in race if race completed. */ draw_status_msg( x_org, y_org, box_width, box_height ); #endif /* Draw preview */ if ( g_game.practicing ) { list_elem_t elem; open_course_data_t *data; elem = listbox_get_current_item( race_listbox ); data = (open_course_data_t*) get_list_elem_data( elem ); current_course = data->course; } else { list_elem_t elem; race_data_t *data; elem = listbox_get_current_item( race_listbox ); data = (race_data_t*) get_list_elem_data( elem ); current_course = data->course; } glDisable( GL_TEXTURE_2D ); glColor4f( 0.0, 0.0, 0.0, 0.3 ); #ifdef __APPLE__ float margin = 4.f * mHeight / 320; float yoffset = 26 * mHeight / 320 + 30 * mHeight / 320; glBegin( GL_QUADS ); { glVertex2f( x_org, y_org + yoffset ); glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset ); glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset+107 * mHeight / 320 ); glVertex2f( x_org, y_org + yoffset+107 * mHeight / 320 ); } glEnd(); #else glBegin( GL_QUADS ); { glVertex2f( x_org+box_width-140, y_org+66 ); glVertex2f( x_org+box_width, y_org+66 ); glVertex2f( x_org+box_width, y_org+66+107 ); glVertex2f( x_org+box_width-140, y_org+66+107 ); } glEnd(); #endif glColor4f( 1.0, 1.0, 1.0, 1.0 ); glEnable( GL_TEXTURE_2D ); if ( !get_texture_binding( current_course, &texobj ) ) { if ( !get_texture_binding( "no_preview", &texobj ) ) { texobj = 0; } } glBindTexture( GL_TEXTURE_2D, texobj ); #ifdef __APPLE__ glBegin( GL_QUADS ); { glTexCoord2d( 0, 0); glVertex2f( x_org + margin, y_org + yoffset+margin ); glTexCoord2d( 1, 0); glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin ); glTexCoord2d( 1, 1); glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin+99 * mHeight / 320 ); glTexCoord2d( 0, 1); glVertex2f( x_org + margin, y_org + yoffset+margin+99 * mHeight / 320 ); } glEnd(); #else glBegin( GL_QUADS ); { glTexCoord2d( 0, 0); glVertex2f( x_org+box_width-136, y_org+70 ); glTexCoord2d( 1, 0); glVertex2f( x_org+box_width-4, y_org+70 ); glTexCoord2d( 1, 1); glVertex2f( x_org+box_width-4, y_org+70+99 ); glTexCoord2d( 0, 1); glVertex2f( x_org+box_width-136, y_org+70+99 ); } glEnd(); #endif } /*---------------------------------------------------------------------------*/ /*! Mode initialization function \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ static void race_select_init(void) { listbox_list_elem_to_string_fptr_t conv_func = NULL; point2d_t dummy_pos = {0, 0}; int i; winsys_set_display_func( main_loop ); winsys_set_idle_func( main_loop ); winsys_set_reshape_func( reshape ); winsys_set_mouse_func( ui_event_mouse_func ); winsys_set_motion_func( ui_event_motion_func ); winsys_set_passive_motion_func( ui_event_motion_func ); plyr = get_player_data( local_player() ); /* Setup the race list */ if ( g_game.practicing ) { g_game.current_event = "__Practice_Event__"; g_game.current_cup = "__Practice_Cup__"; race_list = get_open_courses_list(); conv_func = get_name_from_open_course_data; cup_data = NULL; last_completed_race = NULL; event_data = NULL; } else { event_data = (event_data_t*) get_list_elem_data( get_event_by_name( g_game.current_event ) ); check_assertion( event_data != NULL, "Couldn't find current event." ); cup_data = (cup_data_t*) get_list_elem_data( get_event_cup_by_name( event_data, g_game.current_cup ) ); check_assertion( cup_data != NULL, "Couldn't find current cup." ); race_list = get_cup_race_list( cup_data ); conv_func = get_name_from_race_data; } /* Unless we're coming back from a race, initialize the race data to defaults. */ if ( g_game.prev_mode != GAME_OVER ) { /* Make sure we don't play previously loaded course */ cup_complete = False; /* Initialize the race data */ cur_elem = get_list_head( race_list ); if ( g_game.practicing ) { g_game.race.course = NULL; g_game.race.name = NULL; g_game.race.description = NULL; for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) { g_game.race.herring_req[i] = 0; g_game.race.time_req[i] = 0; g_game.race.score_req[i] = 0; } g_game.race.mirrored = False; g_game.race.conditions = RACE_CONDITIONS_SUNNY; g_game.race.windy = False; g_game.race.snowing = False; } else { /* Not practicing */ race_data_t *data; data = (race_data_t*) get_list_elem_data( cur_elem ); g_game.race = *data; if ( is_cup_complete( event_data, get_event_cup_by_name( event_data, g_game.current_cup ) ) ) { cup_complete = True; last_completed_race = get_list_tail( race_list ); } else { cup_complete = False; last_completed_race = NULL; } } } else { /* Back from a race */ if ( !g_game.race_aborted ) { update_race_results(); } if (!g_game.practicing && !cup_complete) { if ( was_current_race_won() ) { update_for_won_race(); /* Advance to next race */ if ( cur_elem != get_list_tail( race_list ) ) { cur_elem = get_next_list_elem( race_list, cur_elem ); } } else { /* lost race */ plyr->lives -= 1; } print_debug( DEBUG_GAME_LOGIC, "Current lives: %d", plyr->lives ); } } back_btn = button_create( dummy_pos, 80 * mWidth / 480, 48 * mHeight / 320, "button_label", (mWidth>320)?"Back":"<< " ); button_set_hilit_font_binding( back_btn, "button_label_hilit" ); button_set_visible( back_btn, True ); button_set_click_event_cb( back_btn, back_click_cb, NULL ); start_btn = button_create( dummy_pos, 80 * mWidth / 480, 48 * mHeight / 320, "button_label", (mWidth>320)?"Race":" >>" ); button_set_hilit_font_binding( start_btn, "button_label_hilit" ); button_set_disabled_font_binding( start_btn, "button_label_disabled" ); button_set_visible( start_btn, True ); button_set_click_event_cb( start_btn, start_click_cb, NULL ); #ifdef __APPLE__ race_listbox = listbox_create( dummy_pos, mWidth - 170 * mHeight / 320, 44 * mHeight / 320, "course_name_label", race_list, conv_func ); #else race_listbox = listbox_create( dummy_pos, 460 * mHeight / 320, 44 * mHeight / 320, "listbox_item", race_list, conv_func ); #endif listbox_set_current_item( race_listbox, cur_elem ); listbox_set_item_change_event_cb( race_listbox, race_listbox_item_change_cb, NULL ); listbox_set_visible( race_listbox, True ); /* * Create text area */ #ifdef __APPLE__ desc_ta = textarea_create( dummy_pos, 150, 147, "race_description", "" ); #else desc_ta = textarea_create( dummy_pos, 312, 107, "race_description", "" ); #endif if ( g_game.practicing ) { open_course_data_t *data; data = (open_course_data_t*) get_list_elem_data( cur_elem ); textarea_set_text( desc_ta, data->description ); } else { race_data_t *data; data = (race_data_t*) get_list_elem_data( cur_elem ); textarea_set_text( desc_ta, data->description ); } textarea_set_visible( desc_ta, True ); /* * Create state buttons - only if practicing or if cup_complete */ if ( g_game.practicing || cup_complete ) { /* mirror */ mirror_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( mirror_ssbtn, 0, "mirror_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( mirror_ssbtn, 1, "mirror_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( mirror_ssbtn, (int)g_game.race.mirrored ); #ifdef __APPLE__ ssbutton_set_visible( mirror_ssbtn, False ); #else ssbutton_set_visible( mirror_ssbtn, True ); #endif /* conditions */ conditions_ssbtn = ssbutton_create( dummy_pos, 32, 32, 4 ); float border = 2.0; ssbutton_set_state_image( conditions_ssbtn, 0, "conditions_button", make_point2d( (0.0 + border)/64.0, (32.0 + border)/64.0 ), make_point2d( (32.0 - border)/64.0, (64.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 1, "conditions_button", make_point2d( (32.0 + border)/64.0, (0.0 + border)/64.0 ), make_point2d( (64.0 - border)/64.0, (32.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 2, "conditions_button", make_point2d( (32.0 + border)/64.0, (32.0 + border)/64.0 ), make_point2d( (64.0 - border)/64.0, (64.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 3, "conditions_button", make_point2d( (0.0 + border)/64.0, (0.0 + border)/64.0 ), make_point2d( (32.0 - border)/64.0, (32.0 - border)/64.0 ), white ); ssbutton_set_state( conditions_ssbtn, (int)g_game.race.conditions ); ssbutton_set_visible( conditions_ssbtn, True ); #ifdef __APPLE__ ssbutton_set_visible( conditions_ssbtn, False ); #else ssbutton_set_visible( conditions_ssbtn, True ); #endif /* wind */ wind_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( wind_ssbtn, 0, "wind_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( wind_ssbtn, 1, "wind_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( wind_ssbtn, (int)g_game.race.windy ); #ifdef __APPLE__ ssbutton_set_visible( wind_ssbtn, False ); #else ssbutton_set_visible( wind_ssbtn, True ); #endif /* snow */ snow_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( snow_ssbtn, 0, "snow_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( snow_ssbtn, 1, "snow_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( snow_ssbtn, (int)g_game.race.snowing ); #ifdef __APPLE__ ssbutton_set_visible( snow_ssbtn, False ); #else ssbutton_set_visible( snow_ssbtn, True ); #endif /* XXX snow button doesn't do anything, so disable for now */ ssbutton_set_enabled( snow_ssbtn, False ); /* Can't change conditions if in cup mode */ if ( !g_game.practicing ) { ssbutton_set_enabled( conditions_ssbtn, False ); ssbutton_set_enabled( wind_ssbtn, False ); ssbutton_set_enabled( snow_ssbtn, False ); ssbutton_set_enabled( mirror_ssbtn, False ); } } else { conditions_ssbtn = NULL; wind_ssbtn = NULL; snow_ssbtn = NULL; mirror_ssbtn = NULL; } update_race_data(); update_button_enabled_states(); play_music( "start_screen" ); }
/*! Sets the widget positions and draws other on-screen goo \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ static void set_widget_positions_and_draw_decorations() { int w = getparam_x_resolution(); int h = getparam_y_resolution(); int box_width, box_height, box_max_y; int x_org, y_org; char *current_course; GLuint texobj; /* set the dimensions of the box in which all widgets should fit */ box_width = 300; box_height = 310; box_max_y = h - 128; x_org = 10; y_org = h/2 - box_height/2; if ( y_org + box_height > box_max_y ) { y_org = box_max_y - box_height; } button_set_position( back_btn, make_point2d(MARGIN_WIDTH, MARGIN_HEIGHT ) ); button_set_position( start_btn, make_point2d(w - button_get_width( start_btn ) - MARGIN_WIDTH, MARGIN_HEIGHT ) ); listbox_set_position( race_listbox, make_point2d( x_org, y_org + 235 ) ); textarea_set_position( desc_ta, make_point2d( x_org + w - textarea_get_width(desc_ta) - 10, y_org + 26)); if ( g_game.practicing || ( cup_complete && conditions_ssbtn && wind_ssbtn && snow_ssbtn && mirror_ssbtn ) ) { ssbutton_set_position( conditions_ssbtn, make_point2d( x_org + box_width - 4*36 + 4, y_org + 151 ) ); ssbutton_set_position( wind_ssbtn, make_point2d( x_org + box_width - 3*36 + 4 , y_org + 151 ) ); ssbutton_set_position( snow_ssbtn, make_point2d( x_org + box_width - 2*36 + 4, y_org + 151 ) ); ssbutton_set_position( mirror_ssbtn, make_point2d( x_org + box_width - 1*36 + 4, y_org + 151 ) ); } /* Draw text indicating race requirements (if race not completed), or results in race if race completed. */ draw_status_msg( x_org, y_org, box_width, box_height ); /* Draw preview */ if ( g_game.practicing ) { list_elem_t elem; open_course_data_t *data; elem = listbox_get_current_item( race_listbox ); data = (open_course_data_t*) get_list_elem_data( elem ); current_course = data->course; } else { list_elem_t elem; race_data_t *data; elem = listbox_get_current_item( race_listbox ); data = (race_data_t*) get_list_elem_data( elem ); current_course = data->course; } glDisable( GL_TEXTURE_2D ); glColor4f( 0.0, 0.0, 0.0, 0.3 ); #ifdef __APPLE__ float margin = 4.f; float yoffset = 26 + 30; glBegin( GL_QUADS ); { glVertex2f( x_org, y_org + yoffset ); glVertex2f( x_org + 140, y_org + yoffset ); glVertex2f( x_org + 140, y_org + yoffset+107 ); glVertex2f( x_org, y_org + yoffset+107 ); } glEnd(); #else glBegin( GL_QUADS ); { glVertex2f( x_org+box_width-140, y_org+66 ); glVertex2f( x_org+box_width, y_org+66 ); glVertex2f( x_org+box_width, y_org+66+107 ); glVertex2f( x_org+box_width-140, y_org+66+107 ); } glEnd(); #endif glColor4f( 1.0, 1.0, 1.0, 1.0 ); glEnable( GL_TEXTURE_2D ); if ( !get_texture_binding( current_course, &texobj ) ) { if ( !get_texture_binding( "no_preview", &texobj ) ) { texobj = 0; } } glBindTexture( GL_TEXTURE_2D, texobj ); #ifdef __APPLE__ glBegin( GL_QUADS ); { glTexCoord2d( 0, 0); glVertex2f( x_org + margin, y_org + yoffset+margin ); glTexCoord2d( 1, 0); glVertex2f( x_org + 140 - margin, y_org + yoffset+margin ); glTexCoord2d( 1, 1); glVertex2f( x_org + 140 - margin, y_org + yoffset+margin+99 ); glTexCoord2d( 0, 1); glVertex2f( x_org + margin, y_org + yoffset+margin+99 ); } glEnd(); #else glBegin( GL_QUADS ); { glTexCoord2d( 0, 0); glVertex2f( x_org+box_width-136, y_org+70 ); glTexCoord2d( 1, 0); glVertex2f( x_org+box_width-4, y_org+70 ); glTexCoord2d( 1, 1); glVertex2f( x_org+box_width-4, y_org+70+99 ); glTexCoord2d( 0, 1); glVertex2f( x_org+box_width-136, y_org+70+99 ); } glEnd(); #endif }
quadsquare::quadsquare(quadcornerdata* pcd) // Constructor. { pcd->Square = this; // Set static to true if/when this node contains real data, and // not just interpolated values. When static == false, a node // can be deleted by the Update() function if none of its // vertices or children are enabled. Static = false; int i; for (i = 0; i < 4; i++) { Child[i] = (quadsquare*) NULL; } EnabledFlags = 0; for (i = 0; i < 2; i++) { SubEnabledCount[i] = 0; } // Set default vertex positions by interpolating from given corners. // Just bilinear interpolation. Vertex[0].Y = 0.25 * (pcd->Verts[0].Y + pcd->Verts[1].Y + pcd->Verts[2].Y + pcd->Verts[3].Y); Vertex[1].Y = 0.5 * (pcd->Verts[3].Y + pcd->Verts[0].Y); Vertex[2].Y = 0.5 * (pcd->Verts[0].Y + pcd->Verts[1].Y); Vertex[3].Y = 0.5 * (pcd->Verts[1].Y + pcd->Verts[2].Y); Vertex[4].Y = 0.5 * (pcd->Verts[2].Y + pcd->Verts[3].Y); for (i = 0; i < 2; i++) { Error[i] = 0; } for (i = 0; i < 4; i++) { Error[i+2] = fabs((Vertex[0].Y + pcd->Verts[i].Y) - (Vertex[i+1].Y + Vertex[((i+1)&3) + 1].Y)) * 0.25; } // Compute MinY/MaxY based on corner verts. MinY = MaxY = pcd->Verts[0].Y; for (i = 1; i < 4; i++) { float y = pcd->Verts[i].Y; if (y < MinY) MinY = y; if (y > MaxY) MaxY = y; } if ( pcd->Parent == NULL ) { print_debug( DEBUG_QUADTREE, "initializing root node" ); // Initialize texture data if (!get_texture_binding("snow", &(TexId[Snow]))) { TexId[Snow] = 0; } if (!get_texture_binding("ice", &TexId[Ice])) { TexId[Ice] = 0; } if (!get_texture_binding("rock", &TexId[Rock])) { TexId[Rock] = 0; } if ( !get_texture_binding( "terrain_envmap", &EnvmapTexId ) ) { EnvmapTexId = 0; } Terrain = get_course_terrain_data(); } }
void Button::draw() { GLuint texobj; texture_region_t *tex; pp::Font *font=mp_font; glEnable( GL_TEXTURE_2D ); tex = NULL; if ( !m_sensitive ) { if ( m_disabledTex.binding ) { tex = &m_disabledTex; } else if ( m_tex.binding ) { tex = &m_tex; } if ( mp_disabledFont ) { font = mp_disabledFont; } } else if ( m_clicked ) { if ( m_clickedTex.binding ) { tex = &m_clickedTex; } else if ( m_hilitTex.binding ) { tex = &m_hilitTex; } else if ( m_tex.binding ) { tex = &m_tex; } if ( mp_hilitFont) { font = mp_hilitFont; } } else if ( m_focused ) { if ( m_hilitTex.binding ) { tex = &m_hilitTex; } else if ( m_tex.binding ) { tex = &m_tex; } if ( mp_hilitFont ) { font = mp_hilitFont; } } else { if ( m_tex.binding ) { tex = &m_tex; } } if ( tex != NULL ) { if ( !get_texture_binding( tex->binding, &texobj ) ) { print_warning( IMPORTANT_WARNING, "Couldnt get texture object for binding %s", tex->binding ); texobj = 0; } glBindTexture( GL_TEXTURE_2D, texobj ); glColor4dv( (double*) &tex->color ); glBegin( GL_QUADS ); { glTexCoord2f( tex->ll.x, tex->ll.y ); glVertex3f( m_position.x, m_position.y, 0 ); glTexCoord2f( tex->ur.x, tex->ll.y ); glVertex3f( m_position.x + m_size.x, m_position.y, 0 ); glTexCoord2f( tex->ur.x, tex->ur.y ); glVertex3f( m_position.x + m_size.x, m_position.y + m_size.y, 0 ); glTexCoord2f( tex->ll.x, tex->ur.y ); glVertex3f( m_position.x, m_position.y + m_size.y, 0 ); } glEnd(); } if(mp_font!=NULL){ float width = font->advance(mp_label); float asc = font->ascender(); float desc = font->descender(); font->draw(mp_label, m_position.x + m_size.x/2.0 - width/2.0, m_position.y + m_size.y/2.0 - asc/2.0 - desc/2.0); } }