Exemplo n.º 1
0
int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;
    float   r = 0.0f;
    float   dr = 2.0f;
    float   z = -14.0f;
    GLuint  texture;
    int trans = 0;

    /* Initialize KOS */
    dbglog_set_level(DBG_WARNING);
    pvr_init_defaults();

    printf("gltest beginning\n");

    /* Get basic stuff initialized */
    glKosInit();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, vid_mode->width / (GLfloat)vid_mode->height, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_TEXTURE_2D);

    /* Expect CW vertex order */
    glFrontFace(GL_CW);

    /* Enable Transparancy */
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    /* Load a texture and make it look nice */
    loadtxr("/rd/glass.pvr", &texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR);
    glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);


    printf("texture is %08x\n", texture);

    Cube *cubes[4] = {
        new Cube(-5.0f, 0.0f, 0.0f),
        new Cube(5.0f, 0.0f, 0.0f),
        new Cube(0.0f, 5.0f, 0.0f),
        new Cube(0.0f, -5.0f, 0.0f)
    };
    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

    while(1) {
        /* Check key status */
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state) {
            printf("Error reading controller\n");
            break;
        }

        if(state->buttons & CONT_START)
            break;

        if(state->buttons & CONT_DPAD_UP)
            z -= 0.1f;

        if(state->buttons & CONT_DPAD_DOWN)
            z += 0.1f;

        if(state->buttons & CONT_DPAD_LEFT) {
            /* If manual rotation is requested, then stop
               the automated rotation */
            dr = 0.0f;

            for(int i = 0; i < 4; i++)
                cubes[i]->rotate(- 2.0f);

            r -= 2.0f;
        }

        if(state->buttons & CONT_DPAD_RIGHT) {
            dr = 0.0f;

            for(int i = 0; i < 4; i++)
                cubes[i]->rotate(+ 2.0f);

            r += 2.0f;
        }

        if(state->buttons & CONT_A) {
            /* This weird logic is to avoid bouncing back
               and forth before the user lets go of the
               button. */
            if(!(trans & 0x1000)) {
                if(trans == 0)
                    trans = 0x1001;
                else
                    trans = 0x1000;
            }
        }
        else {
            trans &= ~0x1000;
        }

        for(int i = 0; i < 4; i++)
            cubes[i]->rotate(dr);

        r += dr;

        /* Draw four objects */
        glLoadIdentity();
        glTranslatef(0.0f, 0.0f, z);
        glRotatef(r, 0.0f, 1.0f, 0.5f);

        cubes[0]->draw();
        cubes[1]->draw();

        /* Potentially do two as translucent */
        if(trans & 1) {
            glEnable(GL_BLEND);
            glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
            glDisable(GL_CULL_FACE);
        }

        cubes[2]->draw();
        cubes[3]->draw();

        if(trans & 1) {
            glEnable(GL_CULL_FACE);
			glDisable(GL_BLEND);
        }

        /* Finish the frame */
        glutSwapBuffers();            
    }

    for(int i = 0; i < 4; i++)
        delete cubes[i];

	glDeleteTextures(1, &texture);

    return 0;
}
Exemplo n.º 2
0
static int lua_net_connect(lua_State * L)
{
  int res = -1;
  struct netif_list * listhead;
  uint8 ip[4];

  dbglog_set_level(7);

  if (lua_tostring(L, 1) == NULL || dns(lua_tostring(L, 1), ip)) {
    printf("Syntax error : try net_connect your.ip.add.ress\n");
    return 0;
  }

  if (netinit) {
    if (memcmp(ip, "\0\0\0\0", 4)) {
      /* hack so that we keep dcload connection alive during DHCP re-negotiation */
      printf("Set IP : %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
      eth_setip(ip[0], ip[1], ip[2], ip[3]);
    }
    return 0;
  }

  printf("calling eth_init\n");


  if (!netinit) {
    //net_init();

    old_printk_func = 0;

    if (find_adaptator(lua_tostring(L, 2))) {
      lua_settop(L, 0);
      lua_pushstring(L, "No adaptator recognised");
      return 1;
    }

    net_init();
  }
  netinit = 1;
  
  // Find a device for us
  listhead = net_get_if_list();
  LIST_FOREACH(netif, listhead, if_list) {
    if (netif->flags & NETIF_RUNNING)
      break;
  }
  if (netif == NULL) {
    printf("can't find an active KOS network device\n");
    lua_settop(L, 0);
    lua_pushstring(L, "Can't find an active KOS network device");
    return 1;
  }

  if (netif) {
    uint8 mac[6];
    int i;

    printf("Ethernet adapter initialized succesfully !\n");
    res = 0;

    memcpy(eth_mac, netif->mac_addr, sizeof(eth_mac));
    printf("MAC address : ");
    for (i=0; i<6; i++)
      printf("%x ", (int) eth_mac[i]);
    printf("\n");

    printf("Set IP : %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
    eth_setip(ip[0], ip[1], ip[2], ip[3]);

    net_input_set_target(rx_callback);

    if (!fs_init())
      printf("nfs, httpfs, tcpfs and udpfs initialized succesfully\n");
  }

  return 0;
}