int start(int argc, char **argv) { GR_EVENT event; nxeyes_state *state; if(GrOpen() < 0) { printf("Couldn't connect to Nano-X server\n"); return 1; } if(!(state = init())) { printf("Couldn't allocate state structure\n"); return 1; } while(!state->quit) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: state->quit = 1; break; case GR_EVENT_TYPE_MOUSE_POSITION: position_event(&event.mouse, state); break; case GR_EVENT_TYPE_BUTTON_UP: case GR_EVENT_TYPE_BUTTON_DOWN: button_event(&event.button, state); break; case GR_EVENT_TYPE_EXPOSURE: draw_eyes(state, 1); break; #if MW_FEATURE_TIMERS case GR_EVENT_TYPE_TIMER: timer_event(&event.timer, state); break; #endif default: break; } if(state->mouse_moved) { draw_eyes(state, 0); state->mouse_moved = 0; } } GrClose(); free(state); return 0; }
void init() { draw_head(); draw_eyes(); draw_smile(); draw_frown(); glNewList(SMILEY_FACE, GL_COMPILE); glCallList(HEAD); glCallList(EYES); glCallList(SMILE); glEndList(); glNewList(FROWNY_FACE, GL_COMPILE); glCallList(HEAD); glCallList(EYES); glCallList(FROWN); glEndList(); }
void timer_event(GR_EVENT_TIMER *ev, nxeyes_state *state) { if(ev->tid != state->tid) return; /* Must free timer - even though it's fired, the handle and data structure live on. */ GrDestroyTimer(state->tid); state->tid = 0; if(state->eyes_closed) { state->eyes_closed = 0; start_blink_timer(state); } else { state->eyes_closed = 1; start_blink_timer(state); } draw_eyes(state, 1); }
void GreenInvader::draw(float x, float y, int debug){ _x = x; _y = y; GreenInvader inv; glPushMatrix(); glTranslated(x, y, 0.0f); glPushMatrix(); GLfloat material[] = {0.5,1.0,0,1}; GLfloat specular[] = {0,0,0,0}; GLfloat emission[] = {0,0,0,0}; GLfloat shininess[] = {0}; glMaterialfv(GL_FRONT, GL_AMBIENT, material); glMaterialfv(GL_FRONT, GL_DIFFUSE, material); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialfv(GL_FRONT, GL_EMISSION, emission); glMaterialfv(GL_FRONT, GL_SHININESS, shininess); glColor3f(0.5f, 1.0f, 0.0f); glPushMatrix(); if (debug) glutWireSphere(_radius, 13, 5); glPopMatrix(); glPushMatrix(); draw_legs(); // pernas glPopMatrix(); glPushMatrix(); glScalef(2, 1, 2); glTranslated(0,-2,0); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glScalef(6, 1, 2); glTranslated(0,-1,0); //base do corpo glutSolidCube(1); glPopMatrix(); glPushMatrix(); draw_body(); //corpo glPopMatrix(); glPushMatrix(); draw_head(); //cabeca glPopMatrix(); GLfloat eye_ambient[] = {0,0,0,1}; GLfloat eye_diffuse[] = {0,0,0,1}; GLfloat eye_specular[] = {0,0,0,0}; GLfloat eye_emission[] = {0,0,0,0}; GLfloat eye_shininess[] = {0}; glMaterialfv(GL_FRONT, GL_AMBIENT, eye_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, eye_ambient); glMaterialfv(GL_FRONT, GL_SPECULAR, eye_specular); glMaterialfv(GL_FRONT, GL_EMISSION, eye_emission); glMaterialfv(GL_FRONT, GL_SHININESS, eye_shininess); glColor3f(0.0f, 0.0f, 0.0f); //preto glPushMatrix(); draw_eyes(); //olhos glPopMatrix(); glPopMatrix(); glPopMatrix(); }