Changeset 22
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile
r20 r22 1 1 2 SRC = test-map.cpp video.cpp 2 SRC = test-map.cpp video.cpp tiler.cpp 3 3 4 4 all: test-map -
trunk/src/test-map.cpp
r21 r22 1 1 // Test stuff 2 2 3 #ifdef WIN324 # define WIN32_LEAN_AND_MEAN5 # include <windows.h>6 #endif7 #if defined __APPLE__ && defined __MACH__8 # include <OpenGL/gl.h>9 #else10 # define GL_GLEXT_PROTOTYPES11 # include <GL/gl.h>12 # include <GL/glext.h>13 #endif14 15 3 #include <SDL.h> 16 #include <SDL_image.h>17 4 18 5 #include <stdio.h> … … 20 7 21 8 #include "video.h" 9 #include "tiler.h" 22 10 23 /* Storage for one texture */ 24 GLuint texture[1]; 25 26 /* Storage for 3 vertex buffers */ 27 GLuint buflist[3]; 11 /* Global objects */ 12 Video *video; 13 Tiler *tiler; 28 14 29 15 /* Storage for map layers */ … … 31 17 int width = 32, height = 32; 32 18 int nlayers = 0; 33 34 /* Player coordinates */35 int playerx = 0, playery = 0;36 37 // Load Bitmaps And Convert To Textures38 void LoadGLTextures(void)39 {40 SDL_Surface *image1 = IMG_Load("art/test/groundtest.png");41 42 if (!image1)43 {44 SDL_Quit();45 exit(1);46 }47 48 glGenTextures(1, &texture[0]);49 glBindTexture(GL_TEXTURE_2D, texture[0]);50 51 glTexImage2D(GL_TEXTURE_2D, 0, 4, image1->w, image1->h, 0,52 GL_RGBA, GL_UNSIGNED_BYTE, image1->pixels);53 54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);56 };57 58 void MakeVBOs(void)59 {60 glGenBuffers(3, buflist);61 }62 19 63 20 void LoadMap(void) … … 85 42 } 86 43 87 void PutMap(int const *themap, int width, int height)88 {89 // Put map90 float uvs[8 * width * height];91 92 for (int y = 0; y < height; y++)93 for (int x = 0; x < width; x++)94 {95 int tile = themap[width * y + x];96 float ty = .0625f * (tile / 16);97 float tx = .0625f * (tile % 16);98 uvs[8 * (width * y + x) + 0] = tx;99 uvs[8 * (width * y + x) + 1] = ty;100 uvs[8 * (width * y + x) + 2] = tx + .0625f;101 uvs[8 * (width * y + x) + 3] = ty;102 uvs[8 * (width * y + x) + 4] = tx + .0625f;103 uvs[8 * (width * y + x) + 5] = ty + .0625f;104 uvs[8 * (width * y + x) + 6] = tx;105 uvs[8 * (width * y + x) + 7] = ty + .0625f;106 }107 glBindBuffer(GL_ARRAY_BUFFER, buflist[1]);108 glBufferData(GL_ARRAY_BUFFER,109 8 * width * height * sizeof(float), uvs, GL_STATIC_DRAW);110 111 float vertices[8 * width * height];112 for (int y = 0; y < height; y++)113 for (int x = 0; x < width; x++)114 {115 vertices[8 * (width * y + x) + 0] = x * 32;116 vertices[8 * (width * y + x) + 1] = y * 32;117 vertices[8 * (width * y + x) + 2] = x * 32 + 32;118 vertices[8 * (width * y + x) + 3] = y * 32;119 vertices[8 * (width * y + x) + 4] = x * 32 + 32;120 vertices[8 * (width * y + x) + 5] = y * 32 + 32;121 vertices[8 * (width * y + x) + 6] = x * 32;122 vertices[8 * (width * y + x) + 7] = y * 32 + 32;123 }124 glBindBuffer(GL_ARRAY_BUFFER, buflist[0]);125 glBufferData(GL_ARRAY_BUFFER,126 8 * width * height * sizeof(float), vertices, GL_STATIC_DRAW);127 128 int indices[4 * width * height];129 for (int n = 0; n < 4 * width * height; n++)130 indices[n] = n;131 glBindBuffer(GL_ARRAY_BUFFER, buflist[2]);132 glBufferData(GL_ARRAY_BUFFER,133 4 * width * height * sizeof(int), indices, GL_STATIC_DRAW);134 135 glEnableClientState(GL_VERTEX_ARRAY);136 glEnableClientState(GL_TEXTURE_COORD_ARRAY);137 glEnableClientState(GL_INDEX_ARRAY);138 139 glBindTexture(GL_TEXTURE_2D, texture[0]);140 141 glBindBuffer(GL_ARRAY_BUFFER, buflist[0]);142 glVertexPointer(2, GL_FLOAT, 0, NULL);143 glBindBuffer(GL_ARRAY_BUFFER, buflist[1]);144 glTexCoordPointer(2, GL_FLOAT, 0, NULL);145 glBindBuffer(GL_ARRAY_BUFFER, buflist[2]);146 glIndexPointer(GL_INT, 0, NULL);147 148 glDrawArrays(GL_QUADS, 0, 4 * width * height);149 150 glDisableClientState(GL_VERTEX_ARRAY);151 glDisableClientState(GL_TEXTURE_COORD_ARRAY);152 glDisableClientState(GL_INDEX_ARRAY);153 }154 155 44 /* The main drawing function. */ 156 45 void DrawScene() 157 46 { 158 /* 159 int ground[20 * 15] = 160 { 161 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 162 18, 1, 2, 2, 2, 34, 2, 2, 2, 2, 2, 2, 3, 34, 4, 18, 18, 18, 18, 18, 163 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 20, 4, 18, 18, 18, 18, 164 18, 19, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 19, 18, 18, 18, 18, 165 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 18, 18, 18, 18, 166 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 18, 20, 36, 18, 18, 18, 18, 167 18, 33, 2, 2, 2, 2, 2, 2, 2, 2, 34, 2, 35, 2, 36, 18, 18, 18, 18, 18, 168 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 169 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 170 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 171 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 172 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 173 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 174 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 175 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 176 }; 177 178 int l1objects[20 * 15] = 179 { 180 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 181 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 182 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 184 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, 185 0, 0, 0, 0, 49, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 186 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 187 0, 0, 0, 0, 49, 49, 49, 49, 49, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 188 0, 0, 0, 0, 0, 49, 49, 49, 49, 0, 0, 0, 0, 25, 9, 9, 9, 8, 0, 0, 189 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 40, 39, 39, 41, 0, 0, 190 0, 0, 0, 49, 49, 32, 0, 50, 0, 0, 0, 48, 0, 24, 23, 54, 40, 55, 0, 0, 191 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 64, 0, 24, 23, 24, 23, 7, 0, 0, 192 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 38, 24, 23, 7, 0, 0, 193 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 38, 22, 0, 0, 194 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 195 }; 196 */ 197 198 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 199 glLoadIdentity(); 47 video->Clear(); 200 48 201 49 for (int i = 0; i < nlayers; i++) 202 { 203 glPushMatrix(); 204 if (i == 2) 205 glTranslatef(playerx, playery, 0.0f); 206 PutMap(layers[i], width, height); 207 glPopMatrix(); 208 } 50 for (int y = 0; y < height; y++) 51 for (int x = 0; x < width; x++) 52 tiler->AddTile(layers[i][y * width + x], x * 32, y * 32, i); 53 54 /* Test stuff */ 55 int playerx, playery; 56 SDL_GetMouseState(&playerx, &playery); 57 tiler->AddTile(50, playerx, playery, nlayers); 58 59 tiler->Render(); 60 video->Refresh(33.33333f); 209 61 } 210 62 211 63 int main(int argc, char **argv) 212 64 { 213 Video *video = new Video("Deus Hax", 640, 480); 65 video = new Video("Deus Hax", 640, 480); 66 tiler = new Tiler(); 214 67 215 68 int done; 216 69 217 70 /* Loop, drawing and checking events */ 218 LoadGLTextures();219 MakeVBOs();220 71 LoadMap(); 221 72 … … 224 75 { 225 76 DrawScene(); 226 227 video->Refresh(33.33333f);228 229 SDL_GetMouseState(&playerx, &playery);230 77 231 78 /* This could go in a separate function */ … … 245 92 } 246 93 94 delete tiler; 247 95 delete video; 248 96 -
trunk/src/video.cpp
r21 r22 91 91 } 92 92 93 void Video::Clear() 94 { 95 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 96 glLoadIdentity(); 97 } 98 93 99 void Video::Refresh(float milliseconds) 94 100 { -
trunk/src/video.h
r18 r22 10 10 int GetWidth() const; 11 11 int GetHeight() const; 12 void Clear(); 12 13 void Refresh(float milliseconds); 13 14 void FullScreen();
Note: See TracChangeset
for help on using the changeset viewer.