static Glfw.Cursor CreateCursorFrame(float t) { int i = 0, x, y; var buffer = new byte[64 * 64 * 4]; for (y = 0; y < 64; y++) { for (x = 0; x < 64; x++) { buffer[i++] = 255; buffer[i++] = 255; buffer[i++] = 255; buffer[i++] = (byte)(255 * Star(x, y, t)); } } var image = new Glfw.Image { Width = 64, Height = 64, Pixels = buffer }; return(Glfw.CreateCursor(image, image.Width / 2, image.Height / 2)); }
public static Glfw.Image getImage(string path) { Glfw.Image image = new Glfw.Image(); Bitmap bitmap = new Bitmap(path); image.Pixels = TextureLoader.SetImageBuffer(bitmap); image.Height = bitmap.Height; image.Width = bitmap.Width; return(image); }
static void SetIcon(Glfw.Window window, int iconColor) { var pixels = new byte[16 * 16 * 4]; var img = new Glfw.Image { Width = 16, Height = 16, Pixels = pixels }; int index = 0; for (int y = 0; y < img.Width; y++) { for (int x = 0; x < img.Height; x++) { if (m_Logo[y][x] == '0') { pixels[index] = m_IconColors[iconColor][0]; pixels[index + 1] = m_IconColors[iconColor][1]; pixels[index + 2] = m_IconColors[iconColor][2]; pixels[index + 3] = m_IconColors[iconColor][3]; } else { pixels[index] = 0; pixels[index + 1] = 0; pixels[index + 2] = 0; pixels[index + 3] = 0; } index += 4; } } Glfw.SetWindowIcon(window, img); }
static void Main(string[] args) { // Initialize OpenGL Gl.Initialize(); // If the library isn't in the environment path we need to set it Glfw.ConfigureNativesDirectory("..\\..\\libs/glfw-3.2.1.bin.WIN32/lib-mingw"); // Initialize the GLFW if (!Glfw.Init()) { Environment.Exit(-1); } // Create a windowed mode window and its OpenGL context var window = Glfw.CreateWindow(width, height, "Unreal Engine 4"); if (!window) { Glfw.Terminate(); Environment.Exit(-1); } // set window icon Glfw.Image icon = Utils.getImage("..\\..\\res/logo.png"); Glfw.SetWindowIcon(window, icon); // Make the window's context current Glfw.MakeContextCurrent(window); // create loder and renderer Loader loader = new Loader(); // create model RawModel fern = OBJLoader.loadObjModel("fern", loader); ModelTexture fernTexture = new ModelTexture(loader.loadTexture("..\\..\\res/flower.png")); TexturedModel texturedFern = new TexturedModel(fern, fernTexture); texturedFern.modelTexture.shineDamper = 10; texturedFern.modelTexture.reflectivity = 0; texturedFern.modelTexture.isHasTransparency = true; RawModel grass = OBJLoader.loadObjModel("grassModel", loader); ModelTexture grassTexture = new ModelTexture(loader.loadTexture("..\\..\\res/flower.png")); TexturedModel texturedGrass = new TexturedModel(grass, grassTexture); texturedGrass.modelTexture.shineDamper = 10; texturedGrass.modelTexture.reflectivity = 0; texturedGrass.modelTexture.isHasTransparency = true; texturedGrass.modelTexture.isUseFakeLighting = true; RawModel model = OBJLoader.loadObjModel("lowPolyTree", loader); ModelTexture texture = new ModelTexture(loader.loadTexture("..\\..\\res/lowPolyTree.png")); TexturedModel staticModel = new TexturedModel(model, texture); staticModel.modelTexture.shineDamper = 10; staticModel.modelTexture.reflectivity = 0; Entity entity = new Entity(staticModel, new Vertex3f(0, 0, -25), 0, 0, 0, 1); Light light = new Light(new Vertex3f(0, 0, -20), new Vertex3f(1f, 1f, 1f)); Random rand = new Random(); ModelTexture terrainTexture = new ModelTexture(loader.loadTexture("..\\..\\res/grass.png")); terrainTexture.shineDamper = 10; terrainTexture.reflectivity = 0; Terrain terrain = new Terrain(800, 0, loader, terrainTexture); Terrain terrain2 = new Terrain(800, -800, loader, terrainTexture); RawModel tree = OBJLoader.loadObjModel("normal_tree", loader); ModelTexture treeTexture = new ModelTexture(loader.loadTexture("..\\..\\res/normal_tree.png")); TexturedModel texturedTree = new TexturedModel(tree, treeTexture); Random random = new Random(); Camera camera = new Camera(); List <Entity> allCubes = new List <Entity>(); List <Entity> allGrass = new List <Entity>(); List <Entity> allFerns = new List <Entity>(); List <Entity> allTrees = new List <Entity>(); for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allCubes.Add(new Entity(staticModel, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, rand.Next(1, 4))); } for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allGrass.Add(new Entity(texturedGrass, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3)); } for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allFerns.Add(new Entity(texturedFern, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3)); } MasterRenderer renderer = new MasterRenderer(new WinowInfo(width, height)); // Loop until the user closes the window while (!Glfw.WindowShouldClose(window)) { //entity.increasePosition(0, 0, -0.1f); entity.increaseRotation(0, 1, 0); // Render here camera.move(window); renderer.processTerrain(terrain); renderer.processTerrain(terrain2); foreach (Entity cube in allCubes) { renderer.processEntity(cube); } foreach (Entity gr in allGrass) { renderer.processEntity(gr); } foreach (Entity fr in allFerns) { renderer.processEntity(fr); } foreach (Entity tr in allTrees) { renderer.processEntity(tr); } renderer.render(light, camera); //Swap front and back buffers Glfw.SwapBuffers(window); // Poll for and process events Glfw.PollEvents(); } // clean memory renderer.cleanUP(); loader.CleanUp(); // terminate program Glfw.Terminate(); }
static void Main(string[] args) { // Initialize OpenGL Gl.Initialize(); // If the library isn't in the environment path we need to set it Glfw.ConfigureNativesDirectory("..\\..\\libs/glfw-3.2.1.bin.WIN32/lib-mingw"); // Initialize the GLFW if (!Glfw.Init()) { Environment.Exit(-1); } // Create a windowed mode window and its OpenGL context var window = Glfw.CreateWindow(width, height, "Unreal Engine 4"); if (!window) { Glfw.Terminate(); Environment.Exit(-1); } // set window icon Glfw.Image icon = Utils.getImage("..\\..\\res/logo.png"); Glfw.SetWindowIcon(window, icon); // Make the window's context current Glfw.MakeContextCurrent(window); // create shaders after creating opengl context StaticShader shader = new StaticShader(); // create loder and renderer Loader loader = new Loader(); Renderer renderer = new Renderer(shader, new WinowInfo(width, height)); // create model RawModel model = OBJLoader.loadObjModel("dragon", loader); ModelTexture texture = new ModelTexture(loader.loadTexture("..\\..\\res/white.jpg")); TexturedModel staticModel = new TexturedModel(model, texture); Entity entity = new Entity(staticModel, new Vertex3f(0, 0, -25), 0, 0, 0, 2); Light light = new Light(new Vertex3f(0, 0, -20), new Vertex3f(1f, 1f, 1f)); Camera camera = new Camera(); // Loop until the user closes the window while (!Glfw.WindowShouldClose(window)) { entity.increaseRotation(0, 1, 0); // Render here camera.move(window); renderer.prepare(); shader.start(); shader.loadLight(light); shader.loadViewMatrix(camera); renderer.render(entity, shader); shader.stop(); //Swap front and back buffers Glfw.SwapBuffers(window); // Poll for and process events Glfw.PollEvents(); } // clean memory shader.cleanUP(); loader.CleanUp(); // terminate program Glfw.Terminate(); }
static void Main(string[] args) { // Initialize OpenGL Gl.Initialize(); // If the library isn't in the environment path we need to set it Glfw.ConfigureNativesDirectory("..\\..\\libs/glfw-3.2.1.bin.WIN32/lib-mingw"); // Initialize the GLFW if (!Glfw.Init()) { Environment.Exit(-1); } // Create a windowed mode window and its OpenGL context var window = Glfw.CreateWindow(width, height, "Unreal Engine 4"); if (!window) { Glfw.Terminate(); Environment.Exit(-1); } // set window icon Glfw.Image icon = Utils.getImage("..\\..\\res/logo.png"); Glfw.SetWindowIcon(window, icon); // Make the window's context current Glfw.MakeContextCurrent(window); // create loder and renderer Loader loader = new Loader(); // create model RawModel model = OBJLoader.loadObjModel("cube", loader); ModelTexture texture = new ModelTexture(loader.loadTexture("..\\..\\res/rgba.png")); TexturedModel staticModel = new TexturedModel(model, texture); staticModel.modelTexture.shineDamper = 10; staticModel.modelTexture.reflectivity = 1; Entity entity = new Entity(staticModel, new Vertex3f(0, 0, -25), 0, 0, 0, 2); Light light = new Light(new Vertex3f(0, 0, -20), new Vertex3f(1f, 1f, 1f)); Camera camera = new Camera(); List <Entity> allCubes = new List <Entity>(); Random random = new Random(); for (int i = 0; i < 200; i++) { double x = random.NextDouble() * 100 - 50; double y = random.NextDouble() * 100 - 50; double z = random.NextDouble() * -300; allCubes.Add(new Entity(staticModel, new Vertex3f((float)x, (float)y, (float)z), (float)random.NextDouble() * 180, (float)random.NextDouble() * 180, 0, 1)); } MasterRenderer renderer = new MasterRenderer(new WinowInfo(width, height)); // Loop until the user closes the window while (!Glfw.WindowShouldClose(window)) { camera.move(window); // Render here foreach (Entity cube in allCubes) { renderer.processEntity(cube); } renderer.render(light, camera); //Swap front and back buffers Glfw.SwapBuffers(window); // Poll for and process events Glfw.PollEvents(); } // clean memory renderer.cleanUP(); loader.CleanUp(); // terminate program Glfw.Terminate(); }
static void Main(string[] args) { // Initialize OpenGL Gl.Initialize(); // If the library isn't in the environment path we need to set it Glfw.ConfigureNativesDirectory("..\\..\\libs/glfw-3.2.1.bin.WIN32/lib-mingw"); // Initialize the GLFW if (!Glfw.Init()) { Environment.Exit(-1); } // Create a windowed mode window and its OpenGL context var window = Glfw.CreateWindow(width, height, "Unreal Engine 4"); if (!window) { Glfw.Terminate(); Environment.Exit(-1); } // set window icon Glfw.Image icon = Utils.getImage("..\\..\\res/logo.png"); Glfw.SetWindowIcon(window, icon); // Make the window's context current Glfw.MakeContextCurrent(window); // create loder and renderer Loader loader = new Loader(); // create terrain texture pack TerrainTexture backgroundTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/grassy2.png")); TerrainTexture rTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/mud.png")); TerrainTexture gTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/grassFlowers.png")); TerrainTexture bTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/path.png")); TerrainTexturePack texturePack = new TerrainTexturePack(backgroundTexture, rTexture, gTexture, bTexture); // create blend map TerrainTexture blendMap = new TerrainTexture(loader.loadTexture("..\\..\\res/blendMap.png")); // create model RawModel fern = OBJLoader.loadObjModel("fern", loader); ModelTexture fernTexture = new ModelTexture(loader.loadTexture("..\\..\\res/flower.png")); TexturedModel texturedFern = new TexturedModel(fern, fernTexture); texturedFern.modelTexture.shineDamper = 10; texturedFern.modelTexture.reflectivity = 0; texturedFern.modelTexture.isHasTransparency = true; RawModel grass = OBJLoader.loadObjModel("grassModel", loader); ModelTexture grassTexture = new ModelTexture(loader.loadTexture("..\\..\\res/flower.png")); TexturedModel texturedGrass = new TexturedModel(grass, grassTexture); texturedGrass.modelTexture.shineDamper = 10; texturedGrass.modelTexture.reflectivity = 0; texturedGrass.modelTexture.isHasTransparency = true; texturedGrass.modelTexture.isUseFakeLighting = true; RawModel tree = OBJLoader.loadObjModel("normal_tree", loader); ModelTexture treeTexture = new ModelTexture(loader.loadTexture("..\\..\\res/normal_tree.png")); TexturedModel texturedTree = new TexturedModel(tree, treeTexture); texturedTree.modelTexture.shineDamper = 10; texturedTree.modelTexture.reflectivity = 0; RawModel tree2 = OBJLoader.loadObjModel("Spruce", loader); ModelTexture treeTexture2 = new ModelTexture(loader.loadTexture("..\\..\\res/branch.png")); TexturedModel texturedTree2 = new TexturedModel(tree2, treeTexture2); texturedTree2.modelTexture.shineDamper = 10; texturedTree2.modelTexture.reflectivity = 0; RawModel model = OBJLoader.loadObjModel("lowPolyTree", loader); ModelTexture texture = new ModelTexture(loader.loadTexture("..\\..\\res/lowPolyTree.png")); TexturedModel staticModel = new TexturedModel(model, texture); staticModel.modelTexture.shineDamper = 10; staticModel.modelTexture.reflectivity = 0; Entity entity = new Entity(staticModel, new Vertex3f(0, 0, -25), 0, 0, 0, 1); Light light = new Light(new Vertex3f(0, 0, -20), new Vertex3f(1f, 1f, 1f)); Random rand = new Random(); ModelTexture terrainTexture = new ModelTexture(loader.loadTexture("..\\..\\res/grass.png")); terrainTexture.shineDamper = 10; terrainTexture.reflectivity = 0; Terrain terrain = new Terrain(800, 0, loader, texturePack, blendMap); Terrain terrain2 = new Terrain(800, -1600, loader, texturePack, blendMap); RawModel stanfordBunny = OBJLoader.loadObjModel("person", loader); ModelTexture stanfordBunnyTexture = new ModelTexture(loader.loadTexture("..\\..\\res/PlayerTexture.png")); stanfordBunnyTexture.shineDamper = 3; stanfordBunnyTexture.reflectivity = 0.00000000001f; TexturedModel texturedStanfordBunny = new TexturedModel(stanfordBunny, stanfordBunnyTexture); Player player = new Player(texturedStanfordBunny, new Vertex3f(0, 0, -100), 0, 0, 0, 3); Random random = new Random(); Random r = new Random(); Camera camera = new Camera(player, window, winowInfo); List <Entity> allCubes = new List <Entity>(); List <Entity> allGrass = new List <Entity>(); List <Entity> allFerns = new List <Entity>(); List <Entity> allTrees = new List <Entity>(); List <Entity> allNormalTrees = new List <Entity>(); List <Entity> allTrees2 = new List <Entity>(); for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; float ra = r.Next(0, 23); if (ra > 0 & ra < 5) { allCubes.Add(new Entity(staticModel, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, rand.Next(1, 3))); } else if (ra > 5 & ra < 20) { allTrees2.Add(new Entity(texturedTree2, new Vertex3f((float)x, (float)y, (float)z), 90, 0, 0, rand.Next(5, 9))); } else { allNormalTrees.Add(new Entity(texturedTree, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, rand.Next(20, 25))); } } for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allGrass.Add(new Entity(texturedGrass, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3)); } for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allFerns.Add(new Entity(texturedFern, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3)); } MasterRenderer renderer = new MasterRenderer(new WinowInfo(width, height)); lastFrameTime = getCurrentTime(); // Loop until the user closes the window while (!Glfw.WindowShouldClose(window)) { //entity.increasePosition(0, 0, -0.1f); entity.increaseRotation(0, 1, 0); // Render here camera.move(); player.move(window); renderer.processTerrain(terrain); renderer.processTerrain(terrain2); foreach (Entity cube in allCubes) { renderer.processEntity(cube); } foreach (Entity gr in allGrass) { renderer.processEntity(gr); } foreach (Entity fr in allFerns) { renderer.processEntity(fr); } foreach (Entity tr in allTrees) { renderer.processEntity(tr); } foreach (Entity ntr in allNormalTrees) { renderer.processEntity(ntr); } foreach (Entity tr2 in allTrees2) { renderer.processEntity(tr2); } renderer.processEntity(player); renderer.render(light, camera); //Swap front and back buffers Glfw.SwapBuffers(window); // Poll for and process events Glfw.PollEvents(); long currentFrameTime = getCurrentTime(); delta = (currentFrameTime - lastFrameTime) / 1000f; //Console.WriteLine(currentFrameTime + " " + delta + " " + lastFrameTime); lastFrameTime = currentFrameTime; } // clean memory renderer.cleanUP(); loader.CleanUp(); // terminate program Glfw.Terminate(); }