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.
Lecture 5 Rendering lines 1.Steps of line rendering 2.Scan-conversion for line segments 3.A1 tutorial CP411 Computer Graphics Fall 2007 Wilfrid Laurier.
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
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.
GAM532 DPS932 – Week 7 Introduction to shadows. Shadow Effects Light Surface No Shadows Shadows.
Intro to Java Monkey Engine Download JME loads/ loads/
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.
GVE, Hallym University, Song, Chang Geun, Ph.D. 컴퓨터 그래픽스 응용 한림대학교 컴퓨터공학부 송 창근.
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…
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.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
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
1 Viewing & Projective Window Chapter 3. 2 D3D virtual viewpoint Definition: virtual viewpoint is like a camera that was positioned in some where and.
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.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
NoufNaief.net TA: Nouf Al-harbi.
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.
The Framebuffer Hyun-Chul Cho. HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
School of Computer Science
Ogre Overview.
OpenGL and Related Libraries
GAM531 DPS931 – Week 9 OpenGL 4.3 and Direct X 11.
Windows Programming Lecture 13
HW for Computer Graphics
Computer Graphics Introduction to Shaders
Introduction : What is OpenGL
CS 480/680 Computer Graphics GLSL Overview.
OpenGL Programming – Day 1
OpenGL-Rendering Pipeline
Opengl implementation
Presentation transcript:

GAM531 DPS931 – Week 9 OpenGL 4.3 and Direct X 11

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

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

Same Name, Completely Different Classes template<> class Device { 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); }; template <> class Device { 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(); };

Importing DX11 and OpenGL 4.3 #include #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 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); Object Oriented Free Floating Functions

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

Initializing a Render System 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); 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));

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

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

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… struct Color {float r, g, b;}; Color buffer[1920][1080]; float depthBuffer[1920][1080]; Is the pixel closer to the Camera?

Setting Up The Depth Buffer glEnable(GL_DEPTH_TEST); glDepthRange(0, 1); glDepthMask (GL_TRUE); glDepthFunc(GL_LEQUAL); glClearDepth(1.0); 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);

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

Setting Up The View Port glViewport(0,0,win->getSize().x(), win->getSize().y()); 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);

Rendering The World One Object At A Time

Render Processes //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); //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);

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 | WS_VISIBLE); SetWindowPos(wh,HWND_TOP,0, 0,window->getSize().x(), window->getSize().y(), SWP_FRAMECHANGED); window->showWindow(true); ShowCursor(TRUE); } swap->SetFullscreenState(b, 0);

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

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

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