Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned int vbo;
- vector<GLfloat> Vertices;
- void CreateTerrain()
- {
- const int TILE_SIZE = 16;
- const int MAP_WIDTH = 200;
- const int MAP_HEIGHT = 200;
- for(int i = 0; i < MAP_WIDTH; i++)
- {
- float Per = (Perlin(1000 + (i / 50.0))*3000 + 150); // Random Noise function (in testing)
- Per -= fmod(Per, TILE_SIZE);
- for(int j = 0; j < MAP_HEIGHT; j ++)
- {
- Vertices.push_back(i * TILE_SIZE); Vertices.push_back(j * TILE_SIZE);
- Vertices.push_back(i * TILE_SIZE + TILE_SIZE); Vertices.push_back(j * TILE_SIZE);
- Vertices.push_back(i * TILE_SIZE + TILE_SIZE); Vertices.push_back(j * TILE_SIZE + TILE_SIZE);
- Vertices.push_back(i * TILE_SIZE); Vertices.push_back(j * TILE_SIZE + TILE_SIZE);
- }
- }
- glGenBuffers(1, &vbo);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, Vertices.size() * sizeof(GLfloat), &Vertices[0], GL_STATIC_DRAW);
- }
- void Draw()
- {
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glEnableClientState(GL_VERTEX_ARRAY );
- glVertexPointer(2, GL_FLOAT, 0, 0);
- glDrawArrays(GL_QUADS, 0, Vertices.size() / 2);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glDisableClientState(GL_VERTEX_ARRAY );
- }
- void LoadShaders()
- {
- Program program;
- Shader vs;
- Shader fs;
- vs.LoadFile("Vertex.vs");
- fs.LoadFile("Fragment.fs");
- vs.LoadShader(GL_VERTEX_SHADER);
- fs.LoadShader(GL_FRAGMENT_SHADER);
- program.CreateProgram(vs.getShader(), fs.getShader());
- }
- void CameraMovement()
- {
- if(RightDown)
- {
- CameraX += 4;
- }
- else if(LeftDown)
- {
- CameraX -= 4;
- }
- else if(UpPressed)
- {
- CameraY -= 4;
- }
- else if(DownPressed)
- {
- CameraY += 4;
- }
- }
- int main(int argc, char *argv[])
- {
- Init();
- int Frames = 0;
- int Timer = SDL_GetTicks();
- CreateTerrain();
- LoadShaders(); // No Errors returned here
- while(Running)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- CameraMovement();
- glTranslatef(-CameraX, -CameraY, 0); // Just for testing movement, isn't causing major fps drop
- glColor3f(1,0,0);
- Draw();
- glTranslatef(CameraX,CameraY, 0);
- EventLoop();
- if(SDL_GetTicks() - Timer > 1000)
- {
- cout << "FPS " << Frames << endl;
- Timer = SDL_GetTicks();
- Frames = 0;
- }
- Frames++;
- SDL_GL_SwapWindow(window);
- }
- Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement