#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <sstream>
#include <cuda_runtime.h>
#include <array>
#include "Debugging\guicon.h"
#include <SFML\Graphics.hpp>
#include "ResourceManagement\TexturePool.h"
#include "TileMap\TileType.h"
#include "ResourceManagement\ShaderPool.h"
#include "resource.h"
#include "Rendering\Quad.h"
extern void execHelloWorldKernel(int blocks, int threads, int start, int* outVal);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
#ifdef _DEBUG
RedirectIOToConsole();
#endif
sf::RenderWindow window(sf::VideoMode(800, 600), "Space Exodus");
//sf::View view(sf::Vector2f(window.getSize().x / 2.0f, window.getSize().y / 2.0f), (sf::Vector2f)window.getSize());
//view.zoom(2.0f);
//window.setView(view);
const int mapSizeX = 3;
const int mapSizeY = 2;
TileTypes.LoadTileTypes("");
sf::Uint8 testMap[mapSizeX * mapSizeY * 4];
testMap[0] = 0;
testMap[1] = 1;
testMap[2] = 0;
testMap[3] = 0;
testMap[4] = 2;
testMap[5] = 3;
testMap[6] = 0;
testMap[7] = 0;
testMap[8] = 1;
testMap[9] = 2;
testMap[10] = 0;
testMap[11] = 0;
testMap[12] = 3;
testMap[13] = 1;
testMap[14] = 0;
testMap[15] = 0;
testMap[16] = 3;
testMap[17] = 2;
testMap[18] = 0;
testMap[19] = 0;
testMap[20] = 2;
testMap[21] = 0;
testMap[22] = 0;
testMap[23] = 0;
for (int idx = 0; idx < mapSizeX * mapSizeY * 4; idx++)
{
sf::Uint8 floorTileID = rand() % 4;
sf::Uint8 wallTileID = rand() % 4;
int idxMod = idx % 4;
if (idxMod == 0)
{
//testMap[idx] = floorTileID;
printf("RGBA(%d,", testMap[idx]);
}
else if (idxMod == 1)
{
//testMap[idx] = wallTileID;
printf("%d,", testMap[idx]);
}
else if (idxMod == 2)
{
//testMap[idx] = 0;
printf("%d,", testMap[idx]);
}
else
{
//testMap[idx] = 255;
printf("%d) (x=%d, y=%d)\n", testMap[idx], idx % mapSizeX, (int)floor(idx / 4 / mapSizeX));
}
}
sf::Texture renderMapSliceTexture;
sf::Image renderMapSliceImage;
renderMapSliceImage.create(mapSizeX, mapSizeY, testMap);
renderMapSliceTexture.loadFromImage(renderMapSliceImage);
RmTexturePool.LoadAndAddTextureFromFile("SpriteSheet", "SpriteSheet.png");
sf::Font font;
font.loadFromFile("arial.ttf");
int bla = 5;
//RmShaderPool.AddAndCreateShaderFromResource(IDR_OGS_TEST_FRAG, OPENGLSHADER, "testFrag", sf::Shader::Type::Fragment);
RmShaderPool.AddAndCreateShaderFromResource(IDR_OGS_TILEMAP_FRAG, OPENGLSHADER, "LayeredTileShader", sf::Shader::Type::Fragment, true);
execHelloWorldKernel(1, 1, bla, &bla);
printf("adsasd %d\n", bla);
//sf::Sprite spr(*RmTexturePool.GetTexture("TileAir"));
RmShaderPool.GetShader("LayeredTileShader")->setParameter("cameraPos", sf::Vector2f(0.0f, 0.0f));
RmShaderPool.GetShader("LayeredTileShader")->setParameter("tileSheet", *RmTexturePool.GetTexture("SpriteSheet"));
RmShaderPool.GetShader("LayeredTileShader")->setParameter("tileMap", renderMapSliceTexture);
RmShaderPool.GetShader("LayeredTileShader")->setParameter("tileMapDimensions", sf::Vector2f((float)mapSizeX, (float)mapSizeY));
RmShaderPool.GetShader("LayeredTileShader")->setParameter("renderSurfaceDimensions", sf::Vector2f((float)window.getSize().x, (float)window.getSize().y));
RmShaderPool.GetShader("LayeredTileShader")->setParameter("tileSheetDimensions", sf::Vector2f((float)RmTexturePool.GetTexture("SpriteSheet")->getSize().x, (float)RmTexturePool.GetTexture("SpriteSheet")->getSize().y));
Rendering::Quad merp(sf::Vector2f(0, 0), (sf::Vector2f)window.getSize());
sf::Texture renderViewTex;
renderViewTex.create(window.getSize().x, window.getSize().y);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
sf::RenderStates rs;
rs.shader = RmShaderPool.GetShader("LayeredTileShader");
rs.texture = &renderViewTex;
window.draw(merp, rs);
window.display();
}
return 0;
}