GAM531 DPS931 – Week 9 OpenGL 4.3 and Direct X 11.

Slides:



Advertisements
Similar presentations
MVisio: a multi-device 2D/3D graphic engine for PDAs, PCs and CAVEs Achille Peternier, Ph. D. Student VRLab, EPFL, Switzerland 3D Mental Vision.
Advertisements

2006 by Jim X. Chen: 1.1. Review –Graphics commands specify straight lines or other geometric primitives that are scan-converted.
GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
Ben Constable Developer, Internet Explorer Frank Olivier Program Manager, Internet
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Basics. OpenGL. “Hello world” George Georgiev Telerik Corporation
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
Ch 1 Intro to Graphics page 1CS 367 First Day Agenda Best course you have ever had (survey) Info Cards Name, , Nickname C / C++ experience, EOS experience.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
GAM531 DPS931 – Week 1 Introduction. Professors Joseph Hughes Info: scs.senecac.on.ca/~jp.hughes T2104 Roles: Primary Lecturer.
GAM531 DPS931 – Week 9 OpenGL 4.3 and Direct X 11.
CSE 380 – Computer Game Programming Render Threading Portal, by Valve,
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Wilf LaLonde ©2012 Comp Review. Wilf LaLonde ©2012 Comp 4501 Getting Started Shader lights have generally been covered in other courses…
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture.
CHAPTER 2 OpenGL vs. DirectX as API © 2008 Cengage Learning EMEA.
GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object.
Tennis for Two, 1958, by William Higinbotham, Brookhaven National Lab CSE 380 – Computer Game Programming Graphics Device Management.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
GAM531 DPS931 – Week 5 The Scene. Reviewing the Engine Engine DX11 Device GL 4.3 Device ControllerManagerModel DX11 Object GL 4.3 Object DX 11 API GL.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
GAM532 DPS932 – Week 8 Texture Shadow Implementation.
OpenGL-ES 3.0 And Beyond Boston What is EGL? EGL handles: –provides available surface specifications –context management –surface binding –render.
OpenGL Programming Related Links The Official OpenGL Website OpenGL v1.1 Redbook
GAM532 DPS932 – Week 2 Vertex Shaders. The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output.
GAM531 DPS931 – Week 2 Into the Engine. Last Time in GAM531… Engine Core Client Interface Operating System API Device API Engine DX11 Device GL 4.3 Device.
111 Introduction to OGRE3D Programming: Main Loop.
The Cg Runtime Cyril Zeller. Cg Pipeline Graphics programs are written in Cg and compiled to low-level assembly code... Cg Runtime API...
CPSC 453 Tutorial Xin Liu Sep 23, OpenGL An open standard of rendering pipeline A software interface to graphics hardware A useful set of APIs for.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
CSE 380 – Computer Game Programming GUIs for Games.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
CS-321 Dr. Mark L. Hornick 1 Graphics Displays Video graphics adapter Monitor.
GAM666 – Introduction To Game Programming ● DirectDraw, the 2D component of DirectX, uses the term “surface” to mean an area of memory in which pixel data.
Introduction to OpenGL
Programming with Visual Studio MFC and OpenGL. Outline Creating a project Adding OpenGL initialization code and libraries Creating a mouse event Drawing.
Wilf Comp Ambient Occlusion + Order Independent Transparency POST CONCLUSIONS.
SPACE SHUTTLE LAUNCHING GUIDE Mis. V.R.PRATIMA Mr. ASWIN KUMAR PUNITH.K PAUL SUDEEP.G Submitted by.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
School of Computer Science
Window reshaping, Keyboard interaction, Camera, Drawing objects
Advanced Graphics Algorithms Ying Zhu Georgia State University
Ogre Overview.
Introduction to OpenGL
OpenGL and Related Libraries
Starting to draw dealing with Windows which libraries? clipping
Windows Programming Lecture 13
HW for Computer Graphics
Input and Interaction Ed Angel
Input and Interaction Ed Angel
Starting to draw dealing with Windows which libraries? clipping
Computer Graphics Introduction to Shaders
Introduction : What is OpenGL
OpenGL Programming – Day 1
OpenGL-Rendering Pipeline
Opengl implementation
Presentation transcript:

GAM531 DPS931 – Week 9 OpenGL 4.3 and Direct X 11

BlendState <RS> Singleton Texture <RS> Interface Base Class RM = Resource Manager BM = Base Manager IM = Iterative Manager Sh = Shader SO = SceneObject BlendState <RS> Singleton Texture <RS> DX/GL Uniform Buffer m Contains (m = many) RM m Either or (only one) DX/GL API Wrapper BlendStateManager <RS> Mesh <RS> TextureManager <RS> RM DX11 Device GL 4.3 Device IM ActorManager <RS> SO m m Actor <RS> RM ResourceController <RS> SceneController <RS> IM TextureSampler <RS> MeshManager <RS> Engine <RS> CameraManager <RS> m RM m SO SamplerManager <RS> LightManager <RS> IM Camera <RS> VertexFormat <RS> NodeManager <RS> BM MaterialManager <RS> RM VertexFormatManager<RS> RM m ShaderManager <RS> m m SO m m m Sh Sh Light <RS> Node <RS> m Material <RS> VertexShader <RS> FragmentShader <RS>

Cracking Open the Device template <RenderSystem RS> class Device {}; template <> class Device<RS_DX11> { ID3D11Device* dev; … }; template <> class Device<RS_GL43> { HGLRC context; … }; DX11 Device GL 4.3 Device DirectX Device Object Ptr Engine <RS> OpenGL Context Handle

Same Name, Completely Different Classes template <> class Device<RS_DX11> { IDXGISwapChain* swap; ID3D11Device* dev; ID3D11DeviceContext* con; ID3D11RenderTargetView* backbuffer; ID3D11DepthStencilView* depthBuffer; bool active; public: Device() : swap(0), dev(0), con(0), active(false) {} virtual ~Device(); void init(Window*); void release(); void renderStart(); void renderEnd(); void setFullScreen(bool); bool isActive() {return active;} void bindPrimitive(const PrimitiveTopology&); void draw(uint32, uint32); void drawIndexed(uint32, uint32, uint32); IDXGISwapChain* _exposeSwap() {return swap;} ID3D11Device* _exposeDevice() {return dev;} ID3D11DeviceContext* _exposeContext(); }; template<> class Device<RS_GL43> { HGLRC context; HDC hdc; HWND wh; GLuint prim; Window* window; bool active; public: Device() : context(0), hdc(0), active(false), window(0) {} virtual ~Device(); void init(Window*); void release(); void renderStart(); void renderEnd(); void setFullScreen(bool); bool isActive() {return active;} void bindPrimitive(const PrimitiveTopology&); void draw(uint32, uint32); void drawIndexed(uint32, uint32, uint32); };

Importing DX11 and OpenGL 4.3 #include <d3d11.h> #include <d3dx11.h> #include <d3dx10.h> #pragma comment (lib, "d3d11.lib") #pragma comment (lib, "d3dx11.lib") #pragma comment (lib, "d3dx10.lib") #pragma comment (lib, "DXGI.lib") (You must download the GLEW library) #include "GL/glew.h" #include "GL/wglew.h“

Biggest Difference Between GL and DX Object Oriented Free Floating Functions con->OMSetRenderTargets(1, &backbuffer, depthBuffer); dev->CreateDepthStencilView(pDepthStencil, &descDSV,&depthBuffer) dev->CreateTexture2D(&descDepth, NULL, &pDepthStencil ) swap->Release(); context = wglCreateContextAttribsARB(hdc, 0, attribs); glEnable(GL_DEPTH_TEST); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, type, data); wglDeleteContext(context);

Where Do We Start? Device Swap Chain Context Context Free Floating Functions Object Creation Frame Buffer Object Creation Frame Buffer Contains the state of the render system Contains the state of the render system

Initializing a Render System DXGI_SWAP_CHAIN_DESC d; ZeroMemory(&d, sizeof(DXGI_SWAP_CHAIN_DESC)); d.BufferCount = 1; d.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; d.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; d.OutputWindow = w->getWindowID(); d.SampleDesc.Count = 1; d.SampleDesc.Quality = 0; d.Windowed = TRUE d.BufferDesc.Width = w->getSize().x(); d.BufferDesc.Height = w->getSize().y(); d.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; d.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; D3D_FEATURE_LEVEL lev = D3D_FEATURE_LEVEL_11_0; D3D11CreateDeviceAndSwapChain(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, &lev, 1, D3D11_SDK_VERSION, &d, &swap, &dev, 0, &con)); hdc = GetDC(win->getWindowID()); PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = pfd.cDepthBits = 32; pfd.iLayerType = PFD_MAIN_PLANE; int pixFmt = ChoosePixelFormat(hdc, &pfd); ... auto tc = wglCreateContext(hdc); ... glewInit(); int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 4, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_FLAGS_ARB, 0, 0}; context = wglCreateContextAttribsARB(hdc, 0, attribs); wglMakeCurrent(0,0); wglDeleteContext(tc); wglMakeCurrent(hdc, context);

Now We Need to Draw to Something Currently On Screen Currently Being Written To Color buffer[1920][1080]; struct Color {float r, g, b;}; Screen may refresh before we are done rendering!

Setting Up The Back Buffer ID3D11Texture2D* bb; swap->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&bb)); dev->CreateRenderTargetView(bb, 0, &backbuffer)); bb->Release(); con->OMSetRenderTargets(1, &backbuffer, 0); //Was setup sufficiently during context construction glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

Is the pixel closer to the Camera? Rendering With Depth If Object A is rendered, then B, then C… C will be drawn on top of B, which is drawn on top of A… Is the pixel closer to the Camera? struct Color {float r, g, b;}; Color buffer[1920][1080]; float depthBuffer[1920][1080];

Setting Up The Depth Buffer ID3D11Texture2D* pDepthStencil = NULL; D3D11_TEXTURE2D_DESC descDepth; descDepth.Width = d.BufferDesc.Width; descDepth.Height = d.BufferDesc.Height; descDepth.MipLevels = descDepth.ArraySize = 1; descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT descDepth.SampleDesc.Count = 1; descDepth.SampleDesc.Quality = 0; descDepth.Usage = D3D11_USAGE_DEFAULT; descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; descDepth.CPUAccessFlags = 0; descDepth.MiscFlags = 0; dev->CreateTexture2D(&descDepth, 0, &pDepthStencil)); D3D11_DEPTH_STENCIL_DESC dsDesc; ZeroMemory(&dsDesc, sizeof(D3D11_DEPTH_STENCIL_DESC)); dsDesc.DepthEnable = true; dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; dsDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; dsDesc.StencilEnable = true; dsDesc.StencilReadMask = dsDesc.StencilWriteMask = 0xFF; … con->OMSetRenderTargets(1, &backbuffer, depthBuffer); glEnable(GL_DEPTH_TEST); glDepthRange(0, 1); glDepthMask (GL_TRUE); glDepthFunc(GL_LEQUAL); glClearDepth(1.0);

Where to Render To View Port Stats: X = 300 Y = 0 Height = 800 Width = 1200

Setting Up The View Port D3D11_VIEWPORT vp; ZeroMemory(&vp, sizeof(D3D11_VIEWPORT)); vp.TopLeftX = 0; vp.TopLeftY = 0; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.Width = (float)w->getSize().x(); vp.Height = (float)w->getSize().y(); con->RSSetViewports(1, &vp); glViewport(0,0,win->getSize().x(), win->getSize().y());

Rendering The World One Object At A Time

Render Processes //Before each new frame con->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); con->ClearDepthStencilView(depthBuffer, D3D11_CLEAR_DEPTH, 1.0f, 0); //Bind Primitives (more about this later) con->IASetPrimitiveTopology(_dxTranPrim(p.pte)); //Draw an object (more about this later) con->Draw(size, offset); //Flip the back buffer (finish the frame) swap->Present(0, 0); //Before each new frame glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Draw an object (more about this later) glDrawArrays(prim, offset, size); //Flip the back buffer (finish the frame) SwapBuffers(hdc);

Setting Up Full Screen Mode if (b) { SetWindowLongPtr(wh, GWL_STYLE, WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); SetWindowPos(wh, HWND_TOP, 0, 0, window->getSize().x(), window->getSize().y(), SWP_FRAMECHANGED); DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = window->getSize().x(); dmScreenSettings.dmPelsHeight= window->getSize().y(); dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields=DM_BITSPERPEL |DM_PELSWIDTH|DM_PELSHEIGHT; window->showWindow(true); ShowCursor(FALSE); } else { SetWindowLongPtr(wh, GWL_STYLE, WS_OVERLAPPEDWINDOW | SetWindowPos(wh,HWND_TOP,0, 0,window->getSize().x(), ShowCursor(TRUE); } swap->SetFullscreenState(b, 0);

Releasing The Render Systems swap->SetFullscreenState(false, 0); swap->Release(); backbuffer->Release(); depthBuffer->Release(); dev->Release(); con->Release(); wglMakeCurrent(0,0); wglDeleteContext(context); ReleaseDC(wh,hdc);

Checking For Errors auto er = dev->CreateRenderTargetView(bb, 0, &backbuffer)); if(FAILED(er)) { //Error resolution } auto er = glGetError(); if(er != GL_NO_ERROR) { //Error resolution }

To Do Continue work on engine enhancement Read this week’s lab Read this week’s notes Re-implement OpenGL Device functions