1 /*
2  * Copyright (C) 2015-2017, by Laszlo Szeremi under the Boost license.
3  *
4  * Pixel Perfect Engine, graphics.outputScreen module
5  */
6 module PixelPerfectEngine.graphics.outputScreen;
7 
8 //import directx.d2d1;
9 import derelict.sdl2.sdl;
10 import PixelPerfectEngine.graphics.raster;
11 import std.stdio;
12 
13 
14 
15 /*
16  *Output window, uses SDL to output the graphics on screen.
17  */
18 public class OutputScreen : RefreshListener{
19     private SDL_Window* window;
20     private IRaster mainRaster;
21     //private SDL_Texture* sdlTexture;
22     public SDL_Renderer* renderer;
23     private void* mPixels;
24     private int mPitch;
25 
26     //Constructor. x , y : resolution of the window
27     this(const char* title, ushort x, ushort y){
28         SDL_Init(SDL_INIT_VIDEO);
29         window = SDL_CreateWindow(title , SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, x, y, SDL_WINDOW_OPENGL);
30         if (window == null) {
31 //                throw new Exception();
32         }
33         renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
34     }
35     ~this(){
36         SDL_DestroyWindow(window);
37         SDL_Quit();
38 
39     }
40     //Sets main raster.
41     public void setMainRaster(IRaster r){
42         mainRaster = r;
43         //sdlTexture = SDL_CreateTextureFromSurface(renderer, mainRaster.getOutput());
44     }
45 	public static void setScalingQuality(string q){
46 		switch(q){
47 			case "0": SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); break;
48 			case "1": SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); break;
49 			case "2": SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); break;
50 			default: SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); break;
51 		}
52 
53 	}
54 	public static void setDriver(string drv){
55 		switch(drv){
56 			case "direct3d": SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d"); break;
57 			case "opengl": SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); break;
58 			case "opengles2": SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2"); break;
59 			case "opengles": SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles"); break;
60 			case "software": SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); break;
61 			default: break;
62 		}
63 	}
64     public void init(){
65     }
66     //Displays the output from the raster when invoked.
67     public void refreshFinished(){
68 		//SDL_Rect r = SDL_Rect(0,0,640,480); 
69 		SDL_RenderClear(renderer);
70 		SDL_RenderCopy(renderer, mainRaster.getOutput,null,null);
71 		SDL_RenderPresent(renderer);
72 
73     }
74 }