Changeset 16


Ignore:
Timestamp:
Jun 27, 2010, 11:15:55 PM (10 years ago)
Author:
sam
Message:

Upload all vertex buffers on each frame. It is not noticeably slower
for now. Also, fullscreen support.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test-map.cpp

    r14 r16  
    5050{
    5151    glGenBuffers(3, buflist);
    52 
    53     float vertices[8 * 20 * 15];
    54     for (int y = 0; y < 15; y++)
    55         for (int x = 0; x < 20; x++)
    56         {
    57             vertices[8 * (20 * y + x) + 0] = x * 32;
    58             vertices[8 * (20 * y + x) + 1] = y * 32;
    59             vertices[8 * (20 * y + x) + 2] = x * 32 + 32;
    60             vertices[8 * (20 * y + x) + 3] = y * 32;
    61             vertices[8 * (20 * y + x) + 4] = x * 32 + 32;
    62             vertices[8 * (20 * y + x) + 5] = y * 32 + 32;
    63             vertices[8 * (20 * y + x) + 6] = x * 32;
    64             vertices[8 * (20 * y + x) + 7] = y * 32 + 32;
    65         }
    66     glBindBuffer(GL_ARRAY_BUFFER, buflist[0]);
    67     glBufferData(GL_ARRAY_BUFFER,
    68                  8 * 20 * 15 * sizeof(float), vertices, GL_STATIC_DRAW);
    69 
    70     int indices[4 * 20 * 15];
    71     for (int n = 0; n < 4 * 20 * 15; n++)
    72         indices[n] = n;
    73     glBindBuffer(GL_ARRAY_BUFFER, buflist[2]);
    74     glBufferData(GL_ARRAY_BUFFER,
    75                  4 * 20 * 15 * sizeof(int), indices, GL_STATIC_DRAW);
    7652}
    7753
     
    125101                 8 * 20 * 15 * sizeof(float), uvs, GL_STATIC_DRAW);
    126102
     103    float vertices[8 * 20 * 15];
     104    for (int y = 0; y < 15; y++)
     105        for (int x = 0; x < 20; x++)
     106        {
     107            vertices[8 * (20 * y + x) + 0] = x * 32;
     108            vertices[8 * (20 * y + x) + 1] = y * 32;
     109            vertices[8 * (20 * y + x) + 2] = x * 32 + 32;
     110            vertices[8 * (20 * y + x) + 3] = y * 32;
     111            vertices[8 * (20 * y + x) + 4] = x * 32 + 32;
     112            vertices[8 * (20 * y + x) + 5] = y * 32 + 32;
     113            vertices[8 * (20 * y + x) + 6] = x * 32;
     114            vertices[8 * (20 * y + x) + 7] = y * 32 + 32;
     115        }
     116    glBindBuffer(GL_ARRAY_BUFFER, buflist[0]);
     117    glBufferData(GL_ARRAY_BUFFER,
     118                 8 * 20 * 15 * sizeof(float), vertices, GL_STATIC_DRAW);
     119
     120    int indices[4 * 20 * 15];
     121    for (int n = 0; n < 4 * 20 * 15; n++)
     122        indices[n] = n;
     123    glBindBuffer(GL_ARRAY_BUFFER, buflist[2]);
     124    glBufferData(GL_ARRAY_BUFFER,
     125                 4 * 20 * 15 * sizeof(int), indices, GL_STATIC_DRAW);
     126
    127127    glEnableClientState(GL_VERTEX_ARRAY);
    128128    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     
    198198int main(int argc, char **argv)
    199199{
     200  SDL_Surface *video;
    200201  int done;
    201202
     
    208209
    209210  /* Create a 640x480 OpenGL screen */
    210   if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL)
     211  video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
     212  if (!video)
    211213  {
    212214    fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
     
    236238        done = 1;
    237239      if (event.type == SDL_KEYDOWN)
    238         if (event.key.keysym.sym == SDLK_ESCAPE)
     240      {
     241        if (event.key.keysym.sym == SDLK_RETURN)
     242          SDL_WM_ToggleFullScreen(video);
     243        else if (event.key.keysym.sym == SDLK_ESCAPE)
    239244          done = 1;
     245      }
    240246    }
    241247
Note: See TracChangeset for help on using the changeset viewer.