NGLDraw::NGLDraw() { // re-size the widget to that of the parent (in this case the GLFrame passed in on construction) m_rotate=false; // mouse rotation values set to 0 m_spinXFace=0; m_spinYFace=0; m_debug=true; m_debugMode=0; m_rotate=false; // mouse rotation values set to 0 m_spinXFace=0; m_spinYFace=0; // Now we will create a basic Camera from the graphics library // This is a static camera so it only needs to be set once // First create Values for the camera position ngl::Vec3 from(0,2,5); ngl::Vec3 to(0,0,0); ngl::Vec3 up(0,1,0); // now load to our new camera m_cam= new ngl::Camera(from,to,up); // set the shape using FOV 45 Aspect Ratio based on Width and Height // The final two are near and far clipping planes of 0.5 and 10 m_cam->setShape(45,(float)float(720/576),0.05,350); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Grey Background // enable depth testing for drawing glEnable(GL_DEPTH_TEST); // now to load the shader and set the values // grab an instance of shader manager ngl::ShaderLib *shader=ngl::ShaderLib::instance(); // we are creating a shader for Pass 1 shader->createShaderProgram("Pass1"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("Pass1Vertex",ngl::VERTEX); shader->attachShader("Pass1Fragment",ngl::FRAGMENT); // attach the source shader->loadShaderSource("Pass1Vertex","shaders/Pass1Vert.glsl"); shader->loadShaderSource("Pass1Fragment","shaders/Pass1Frag.glsl"); // compile the shaders shader->compileShader("Pass1Vertex"); shader->compileShader("Pass1Fragment"); // add them to the program shader->attachShaderToProgram("Pass1","Pass1Vertex"); shader->attachShaderToProgram("Pass1","Pass1Fragment"); // shader->bindFragDataLocation("Pass1",0,"pointDeferred"); // shader->bindFragDataLocation("Pass1",1,"normalDeferred"); // shader->bindFragDataLocation("Pass1",2,"colourDeferred"); // shader->bindFragDataLocation("Pass1",3,"shadingDeferred"); shader->linkProgramObject("Pass1"); shader->use("Pass1"); // we are creating a shader for Pass 2 shader->createShaderProgram("Pass2"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("Pass2Vertex",ngl::VERTEX); shader->attachShader("Pass2Fragment",ngl::FRAGMENT); // attach the source shader->loadShaderSource("Pass2Vertex","shaders/Pass2Vert.glsl"); shader->loadShaderSource("Pass2Fragment","shaders/Pass2Frag.glsl"); // compile the shaders shader->compileShader("Pass2Vertex"); shader->compileShader("Pass2Fragment"); // add them to the program shader->attachShaderToProgram("Pass2","Pass2Vertex"); shader->attachShaderToProgram("Pass2","Pass2Fragment"); shader->linkProgramObject("Pass2"); shader->use("Pass2"); shader->setShaderParam1i("pointTex",0); shader->setShaderParam1i("normalTex",1); shader->setShaderParam1i("colourTex",2); shader->setShaderParam1i("lightPassTex",3); shader->setShaderParam1i("diffusePassTex",4); // we are creating a shader for Debug pass shader->createShaderProgram("Debug"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("DebugVertex",ngl::VERTEX); shader->attachShader("DebugFragment",ngl::FRAGMENT); // attach the source shader->loadShaderSource("DebugVertex","shaders/DebugVert.glsl"); shader->loadShaderSource("DebugFragment","shaders/DebugFrag.glsl"); // compile the shaders shader->compileShader("DebugVertex"); shader->compileShader("DebugFragment"); // add them to the program shader->attachShaderToProgram("Debug","DebugVertex"); shader->attachShaderToProgram("Debug","DebugFragment"); shader->linkProgramObject("Debug"); shader->use("Debug"); shader->setShaderParam1i("pointTex",0); shader->setShaderParam1i("normalTex",1); shader->setShaderParam1i("colourTex",2); shader->setShaderParam1i("lightPassTex",3); shader->setShaderParam1i("diffusePassTex",4); shader->setRegisteredUniform1i("mode",1); // we are creating a shader for Lighting pass shader->createShaderProgram("Lighting"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("LightingVertex",ngl::VERTEX); shader->attachShader("LightingFragment",ngl::FRAGMENT); // attach the source shader->loadShaderSource("LightingVertex","shaders/LightingPassVert.glsl"); shader->loadShaderSource("LightingFragment","shaders/LightingPassFrag.glsl"); // compile the shaders shader->compileShader("LightingVertex"); shader->compileShader("LightingFragment"); // add them to the program shader->attachShaderToProgram("Lighting","LightingVertex"); shader->attachShaderToProgram("Lighting","LightingFragment"); shader->linkProgramObject("Lighting"); shader->use("Lighting"); shader->setShaderParam1i("pointTex",0); shader->setShaderParam1i("normalTex",1); shader->setShaderParam1i("colourTex",2); shader->setShaderParam1i("lightPassTex",3); shader->setShaderParam2f("wh",720,576); m_text = new ngl::Text("font/arial.ttf",14); m_text->setScreenSize(720,576); m_screenQuad = new ScreenQuad("Debug"); // as re-size is not explicitly called we need to do this. glViewport(0, 0, 720,576); ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance(); prim->createSphere("sphere",0.5,50); prim->createSphere("lightSphere",0.1,10); prim->createCylinder("cylinder",0.5,1.4,40,40); prim->createCone("cone",0.5,1.4,20,20); prim->createDisk("disk",0.8,120); prim->createTorus("torus",0.15,0.4,40,40); prim->createTrianglePlane("plane",14,14,80,80,ngl::Vec3(0,1,0)); createFrameBuffer(); printFrameBufferInfo(m_gbuffer); printFrameBufferInfo(m_lightBuffer); }
void NGLScene::initializeGL() { // we must call this first before any other GL commands to load and link the // gl commands from the lib, if this is not done program will crash ngl::NGLInit::instance(); // Now we will create a basic Camera from the graphics library // This is a static camera so it only needs to be set once // First create Values for the camera position ngl::Vec3 from(0.0f,2.0f,5.0f); ngl::Vec3 to(0.0f,0.0f,0.0f); ngl::Vec3 up(0.0f,1.0f,0.0f); // now load to our new camera m_cam.set(from,to,up); // set the shape using FOV 45 Aspect Ratio based on Width and Height // The final two are near and far clipping planes of 0.5 and 10 m_cam.setShape(45.0f,(float)float(width()/height()),0.05f,350.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Grey Background // enable depth testing for drawing glEnable(GL_DEPTH_TEST); // enable multisampling for smoother drawing glEnable(GL_MULTISAMPLE); // now to load the shader and set the values // grab an instance of shader manager ngl::ShaderLib *shader=ngl::ShaderLib::instance(); // we are creating a shader for Pass 1 shader->createShaderProgram("Pass1"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("Pass1Vertex",ngl::ShaderType::VERTEX); shader->attachShader("Pass1Fragment",ngl::ShaderType::FRAGMENT); // attach the source shader->loadShaderSource("Pass1Vertex","shaders/Pass1Vert.glsl"); shader->loadShaderSource("Pass1Fragment","shaders/Pass1Frag.glsl"); // compile the shaders shader->compileShader("Pass1Vertex"); shader->compileShader("Pass1Fragment"); // add them to the program shader->attachShaderToProgram("Pass1","Pass1Vertex"); shader->attachShaderToProgram("Pass1","Pass1Fragment"); // shader->bindFragDataLocation("Pass1",0,"pointDeferred"); // shader->bindFragDataLocation("Pass1",1,"normalDeferred"); // shader->bindFragDataLocation("Pass1",2,"colourDeferred"); // shader->bindFragDataLocation("Pass1",3,"shadingDeferred"); shader->linkProgramObject("Pass1"); shader->use("Pass1"); // we are creating a shader for Pass 2 shader->createShaderProgram("Pass2"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("Pass2Vertex",ngl::ShaderType::VERTEX); shader->attachShader("Pass2Fragment",ngl::ShaderType::FRAGMENT); // attach the source shader->loadShaderSource("Pass2Vertex","shaders/Pass2Vert.glsl"); shader->loadShaderSource("Pass2Fragment","shaders/Pass2Frag.glsl"); // compile the shaders shader->compileShader("Pass2Vertex"); shader->compileShader("Pass2Fragment"); // add them to the program shader->attachShaderToProgram("Pass2","Pass2Vertex"); shader->attachShaderToProgram("Pass2","Pass2Fragment"); shader->linkProgramObject("Pass2"); shader->use("Pass2"); shader->setShaderParam1i("pointTex",0); shader->setShaderParam1i("normalTex",1); shader->setShaderParam1i("colourTex",2); shader->setShaderParam1i("lightPassTex",3); shader->setShaderParam1i("diffusePassTex",4); // we are creating a shader for Debug pass shader->createShaderProgram("Debug"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("DebugVertex",ngl::ShaderType::VERTEX); shader->attachShader("DebugFragment",ngl::ShaderType::FRAGMENT); // attach the source shader->loadShaderSource("DebugVertex","shaders/DebugVert.glsl"); shader->loadShaderSource("DebugFragment","shaders/DebugFrag.glsl"); // compile the shaders shader->compileShader("DebugVertex"); shader->compileShader("DebugFragment"); // add them to the program shader->attachShaderToProgram("Debug","DebugVertex"); shader->attachShaderToProgram("Debug","DebugFragment"); shader->linkProgramObject("Debug"); shader->use("Debug"); shader->setShaderParam1i("pointTex",0); shader->setShaderParam1i("normalTex",1); shader->setShaderParam1i("colourTex",2); shader->setShaderParam1i("lightPassTex",3); shader->setShaderParam1i("diffusePassTex",4); shader->setRegisteredUniform1i("mode",1); // we are creating a shader for Lighting pass shader->createShaderProgram("Lighting"); // now we are going to create empty shaders for Frag and Vert shader->attachShader("LightingVertex",ngl::ShaderType::VERTEX); shader->attachShader("LightingFragment",ngl::ShaderType::FRAGMENT); // attach the source shader->loadShaderSource("LightingVertex","shaders/LightingPassVert.glsl"); shader->loadShaderSource("LightingFragment","shaders/LightingPassFrag.glsl"); // compile the shaders shader->compileShader("LightingVertex"); shader->compileShader("LightingFragment"); // add them to the program shader->attachShaderToProgram("Lighting","LightingVertex"); shader->attachShaderToProgram("Lighting","LightingFragment"); shader->linkProgramObject("Lighting"); shader->use("Lighting"); shader->setShaderParam1i("pointTex",0); shader->setShaderParam1i("normalTex",1); shader->setShaderParam1i("colourTex",2); shader->setShaderParam1i("lightPassTex",3); shader->setShaderParam2f("wh",width()*devicePixelRatio(),height()*devicePixelRatio()); m_text.reset(new ngl::Text(QFont("Arial",14))); m_text->setScreenSize(width(),height()); m_screenQuad = new ScreenQuad("Debug"); ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance(); prim->createSphere("sphere",0.5f,50.0f); prim->createSphere("lightSphere",0.1f,10.0f); prim->createCylinder("cylinder",0.5f,1.4f,40.0f,40.0f); prim->createCone("cone",0.5f,1.4f,20.0f,20.0f); prim->createDisk("disk",0.8f,120.0f); prim->createTorus("torus",0.15f,0.4f,40.0f,40.0f); prim->createTrianglePlane("plane",14.0f,14.0f,80.0f,80.0f,ngl::Vec3(0.0f,1.0f,0.0f)); createFrameBuffer(); printFrameBufferInfo(m_gbuffer); printFrameBufferInfo(m_lightBuffer); m_fpsTimer =startTimer(0); }