opengl将画面渲染到屏幕的指定区域和多屏渲染

分别将画面渲染到屏幕的左上,坐下,右上,右下区域   效果图:




多屏渲染效果图:


原理见代码注释


[cpp]  view plain  copy
  1. #include "FullScreenQuad.h"  
  2.   
  3.   
  4. void FullScreenQuad::Init()  
  5. {  
  6.     glGenBuffers(1, &mVBO);  
  7.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  8.     glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 20, nullptr, GL_STATIC_DRAW);  
  9.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  10. }  
  11.   
  12. //绘制一个铺满屏幕的四边形  
  13. void FullScreenQuad::Draw(GLint posLoc, GLint texcoordLoc)  
  14. {  
  15.     //draw fullscreen  
  16.     float vertices[] = {  
  17.         -0.5f,-0.5f,-1.0f,0.0f,0.0f,  
  18.         0.5f,-0.5f,-1.0f,1.0f,0.0f,  
  19.         0.5f,0.5f,-1.0f,1.0f,1.0f,  
  20.         -0.5f,0.5f,-1.0f,0.0f,1.0f  
  21.     };  
  22.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);//绑定到vbo  
  23.     glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 20, vertices, GL_STATIC_DRAW);//顶点数据上传至显卡  
  24.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  25.   
  26.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  27.     glEnableVertexAttribArray(posLoc);//启用顶点坐标属性  
  28.     //指定顶点数据在VBO中的入口地址  
  29.     glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, 0);  
  30.     glEnableVertexAttribArray(texcoordLoc);//启用顶点纹理坐标属性  
  31.     //指定顶点纹理坐标在VBO中的入口地址  
  32.     glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (void*)(sizeof(float)*3));  
  33.     glDrawArrays(GL_QUADS, 0, 4);  
  34.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  35. }  
  36.   
  37.   
  38. //绘制左上角四分之一的矩形   
  39. void FullScreenQuad::DrawToLeftTop(GLint posLoc, GLint texcoordLoc)  
  40. {  
  41.        
  42.     float vertices[] = {  
  43.         -0.5f,0.0f,-1.0f,0.0f,0.0f,  
  44.         0.0f,0.0f,-1.0f,1.0f,0.0f,  
  45.         0.0f,0.5f,-1.0f,1.0f,1.0f,  
  46.         -0.5f,0.5f,-1.0f,0.0f,1.0f  
  47.     };  
  48.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  49.     glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 20, vertices, GL_STATIC_DRAW);  
  50.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  51.   
  52.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  53.     glEnableVertexAttribArray(posLoc);  
  54.     glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, 0);  
  55.   
  56.     glEnableVertexAttribArray(texcoordLoc);  
  57.     glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (void*)(sizeof(float) * 3));  
  58.     glDrawArrays(GL_QUADS, 0, 4);  
  59.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  60. }  
  61.   
  62.   
  63. //绘制左下角四分之的矩形  
  64. void FullScreenQuad::DrawToLeftBottom(GLint posLoc, GLint texcoordLoc)  
  65. {  
  66.       
  67.     float vertices[] = {  
  68.         -0.5f,-0.5f,-1.0f,0.0f,0.0f,  
  69.         0.0f,-0.5f,-1.0f,1.0f,0.0f,  
  70.         0.0f,0.0f,-1.0f,1.0f,1.0f,  
  71.         -0.5f,0.0f,-1.0f,0.0f,1.0f  
  72.     };  
  73.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  74.     glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 20, vertices, GL_STATIC_DRAW);  
  75.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  76.   
  77.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  78.     glEnableVertexAttribArray(posLoc);  
  79.     glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, 0);  
  80.     glEnableVertexAttribArray(texcoordLoc);  
  81.     glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (void*)(sizeof(float) * 3));  
  82.     glDrawArrays(GL_QUADS, 0, 4);  
  83.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  84. }  
  85.   
  86.   
  87. //绘制右上角四分之一的矩形  
  88. void FullScreenQuad::DrawToRightTop(GLint posLoc, GLint texcoordLoc)  
  89. {  
  90.       
  91.     float vertices[] = {  
  92.         0.0f,-0.0f,-1.0f,0.0f,0.0f,  
  93.         0.5f,-0.0f,-1.0f,1.0f,0.0f,  
  94.         0.5f,0.5f,-1.0f,1.0f,1.0f,  
  95.         0.0f,0.5f,-1.0f,0.0f,1.0f  
  96.     };  
  97.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  98.     glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 20, vertices, GL_STATIC_DRAW);  
  99.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  100.   
  101.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  102.     glEnableVertexAttribArray(posLoc);  
  103.     glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, 0);  
  104.     glEnableVertexAttribArray(texcoordLoc);  
  105.     glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (void*)(sizeof(float) * 3));  
  106.     glDrawArrays(GL_QUADS, 0, 4);  
  107.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  108. }  
  109.   
  110. //绘制右下角四分之的矩形  
  111. void FullScreenQuad::DrawToRightBottom(GLint posLoc, GLint texcoordLoc)  
  112. {  
  113.   
  114.     float vertices[] = {  
  115.         0.0f,-0.5f,-1.0f,0.0f,0.0f,  
  116.         0.5f,-0.5f,-1.0f,1.0f,0.0f,  
  117.         0.5f,0.0f,-1.0f,1.0f,1.0f,  
  118.         0.0f,0.0f,-1.0f,0.0f,1.0f  
  119.     };  
  120.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  121.     glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 20, vertices, GL_STATIC_DRAW);  
  122.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  123.   
  124.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);  
  125.     glEnableVertexAttribArray(posLoc);  
  126.     glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, 0);  
  127.     glEnableVertexAttribArray(texcoordLoc);  
  128.     glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (void*)(sizeof(float) * 3));  
  129.     glDrawArrays(GL_QUADS, 0, 4);  
  130.     glBindBuffer(GL_ARRAY_BUFFER, 0);  
  131. }  

渲染入口

渲染步骤

一,使用带光照效果的shader

1,首先创建一个fbo

2,在此fbo中绘制三个带光照效果的立方体(每个立方体都有各自的模型矩阵和法线矩阵)

3,分别设置三个立方体的光源并绘制

二,切换shader,使用绘制四边形的shader

4,分别在屏幕的左上,左下,右上,右下绘制四个四边形

5,将此前绘制在fbo中的内容作为纹理贴在绘制的四个四边形中


[cpp]  view plain  copy
  1. #include <windows.h>  
  2. #include "glew.h"  
  3. #include <stdio.h>  
  4. #include <math.h>  
  5. #include "utils.h"  
  6. #include "GPUProgram.h"  
  7. #include "ObjModel.h"  
  8. #include "FBO.h"  
  9. #include "FullScreenQuad.h"  
  10. #include "Glm/glm.hpp"  
  11. #include "Glm/ext.hpp"  
  12. #pragma comment(lib,"opengl32.lib")  
  13. #pragma comment(lib,"glew32.lib")  
  14.   
  15. LRESULT CALLBACK GLWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  
  16. {  
  17.     switch (msg)  
  18.     {  
  19.     case WM_CLOSE:  
  20.         PostQuitMessage(0);  
  21.         break;  
  22.     }  
  23.     return DefWindowProc(hwnd,msg,wParam,lParam);  
  24. }  
  25.   
  26.   
  27. INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)  
  28. {  
  29.     WNDCLASSEX wndClass;  
  30.     wndClass.cbClsExtra = 0;  
  31.     wndClass.cbSize = sizeof(WNDCLASSEX);  
  32.     wndClass.cbWndExtra = 0;  
  33.     wndClass.hbrBackground = NULL;  
  34.     wndClass.hCursor = LoadCursor(NULL,IDC_ARROW);  
  35.     wndClass.hIcon = NULL;  
  36.     wndClass.hIconSm = NULL;  
  37.     wndClass.hInstance = hInstance;  
  38.     wndClass.lpfnWndProc=GLWindowProc;  
  39.     wndClass.lpszClassName = L"OpenGL";  
  40.     wndClass.lpszMenuName = NULL;  
  41.     wndClass.style = CS_VREDRAW | CS_HREDRAW;  
  42.     ATOM atom = RegisterClassEx(&wndClass);  
  43.   
  44.     RECT rect;  
  45.     rect.left = 0;  
  46.     rect.top = 0;  
  47.     rect.right = 800;  
  48.     rect.bottom = 600;  
  49.     AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);  
  50.     HWND hwnd = CreateWindowEx(NULL, L"OpenGL", L"RenderWindow", WS_OVERLAPPEDWINDOW, 100, 100, rect.right-rect.left, rect.bottom-rect.top, NULL, NULL, hInstance, NULL);  
  51.     HDC dc = GetDC(hwnd);  
  52.     PIXELFORMATDESCRIPTOR pfd;  
  53.     memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));  
  54.     pfd.nVersion = 1;  
  55.     pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DOUBLEBUFFER;  
  56.     pfd.iLayerType = PFD_MAIN_PLANE;  
  57.     pfd.iPixelType = PFD_TYPE_RGBA;  
  58.     pfd.cColorBits = 32;  
  59.     pfd.cDepthBits = 24;  
  60.     pfd.cStencilBits = 8;  
  61.   
  62.     int pixelFormatID = ChoosePixelFormat(dc, &pfd);  
  63.   
  64.     SetPixelFormat(dc,pixelFormatID,&pfd);  
  65.   
  66.     HGLRC rc = wglCreateContext(dc);  
  67.     wglMakeCurrent(dc, rc);  
  68.     GetClientRect(hwnd, &rect);  
  69.     int viewportWidth = rect.right - rect.left, viewportHeight = rect.bottom - rect.top;  
  70.     glewInit();  
  71.   
  72.     GPUProgram fsqProgram;  
  73.     fsqProgram.AttachShader(GL_VERTEX_SHADER, "Debug/res/shader/fullscreenquad.vs");  
  74.     fsqProgram.AttachShader(GL_FRAGMENT_SHADER, "Debug/res/shader/fullscreenquad.fs");  
  75.     fsqProgram.Link();  
  76.   
  77.     fsqProgram.DetectAttribute("pos");  
  78.     fsqProgram.DetectAttribute("texcoord");  
  79.     fsqProgram.DetectUniform("U_MainTexture");  
  80.   
  81.     GPUProgram gpuProgram;  
  82.     gpuProgram.AttachShader(GL_VERTEX_SHADER, "Debug/res/shader/Light.vs");  
  83.     gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "Debug/res/shader/Light.fs");  
  84.     gpuProgram.Link();  
  85.   
  86.     gpuProgram.DetectAttribute("pos");  
  87.     gpuProgram.DetectAttribute("texcoord");  
  88.     gpuProgram.DetectAttribute("normal");  
  89.     gpuProgram.DetectUniform("M");  
  90.     gpuProgram.DetectUniform("V");  
  91.     gpuProgram.DetectUniform("P");  
  92.     gpuProgram.DetectUniform("NM");  
  93.     gpuProgram.DetectUniform("U_AmbientLightColor");  
  94.     gpuProgram.DetectUniform("U_AmbientMaterial");  
  95.     gpuProgram.DetectUniform("U_DiffuseLightColor");  
  96.     gpuProgram.DetectUniform("U_DiffuseMaterial");  
  97.     gpuProgram.DetectUniform("U_SpecularLightColor");  
  98.     gpuProgram.DetectUniform("U_SpecularMaterial");  
  99.     gpuProgram.DetectUniform("U_LightPos");  
  100.     gpuProgram.DetectUniform("U_EyePos");  
  101.     gpuProgram.DetectUniform("U_LightDirection");  
  102.     gpuProgram.DetectUniform("U_Cutoff");  
  103.     gpuProgram.DetectUniform("U_DiffuseIntensity");  
  104.     //init 3d model  
  105.     ObjModel cube;  
  106.     cube.Init("Debug/res/model/Cube.obj");  
  107.   
  108.     //摄像机矩阵的单位矩阵  
  109.     float identity[] = {  
  110.         1.0f,0,0,0,  
  111.         0,1.0f,0,0,  
  112.         0,0,1.0f,0,  
  113.         0,0,0,1.0f  
  114.     };  
  115.     float ambientLightColor[] = { 0.4f,0.4f,0.4f,1.0f };//环境光颜色  
  116.     float ambientMaterial[] = { 0.2f,0.2f,0.2f,1.0f };//环境光材质  
  117.     float diffuseLightColor[] = { 1.0f,1.0f,1.0f,1.0f };//漫反射光颜色  
  118.     float diffuseMaterial[] = { 0.6f,0.6f,0.6f,1.0f };//漫反射光材质  
  119.     float diffuseIntensity = 1.0f;//漫反射光强度  
  120.     float specularLightColor[] = { 1.0f,1.0f,1.0f,1.0f };//环境光颜色  
  121.     float specularMaterial[] = { 1.0f,1.0f,1.0f,1.0f };//环境光材质  
  122.     float lightPos[] = { 0.0f,1.5f,0.0f,0.0f };//光源位置  
  123.     float spotLightDirection[] = { 0.0f,-1.0f,0.0f,128.0f };//聚光灯中心线向量  
  124.     float spotLightCutoff = 0.0f;// 聚光灯中心线向量和入射光线最大夹角  
  125.     float eyePos[] = { 0.0f,0.0f,0.0f };//眼睛的位置  
  126.   
  127.     //模型矩阵  
  128.     glm::mat4 model1 = glm::translate<float>(-2.0f, 0.0f, -6.0f)*glm::rotate(-30.0f,1.0f,1.0f,1.0f);  
  129.     glm::mat4 model2 = glm::translate<float>(0.0f, 0.0f, -6.0f)*glm::rotate(-30.0f,1.0f,1.0f,1.0f);  
  130.     glm::mat4 model3 = glm::translate<float>(2.0f, 0.0f, -6.0f)*glm::rotate(-30.0f,1.0f,1.0f,1.0f);  
  131.     //投影矩阵  
  132.     glm::mat4 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f);  
  133.   
  134.     //将法线转换到世界空间的变换矩阵  
  135.     glm::mat4 normalMatrix1 = glm::inverseTranspose(model1);  
  136.     glm::mat4 normalMatrix2 = glm::inverseTranspose(model2);  
  137.     glm::mat4 normalMatrix3 = glm::inverseTranspose(model3);  
  138.   
  139.   
  140.     FullScreenQuad fsq;  
  141.     fsq.Init();  
  142.     FBO fbo;  
  143.     fbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight);  
  144.     fbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight);  
  145.     fbo.Finish();  
  146.   
  147.     //glClearColor(41.0f/255.0f,  71.0f/255.0f, 121.0f / 255.0f, 1.0f);  
  148.     ShowWindow(hwnd, SW_SHOW);  
  149.     UpdateWindow(hwnd);  
  150.   
  151.     bool isFullScreen = true;  
  152.     MSG msg;  
  153.     while (true)  
  154.     {  
  155.         if (PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))  
  156.         {  
  157.             if (msg.message==WM_QUIT)  
  158.             {  
  159.                 break;  
  160.             }  
  161.             TranslateMessage(&msg);  
  162.             DispatchMessage(&msg);  
  163.         }  
  164.         //绑定fbo----将绘制的场景绑定到FBO  
  165.         fbo.Bind();  
  166.   
  167.         glClearColor(0.0f,0.0f,0.0f,1.0f);  
  168.         //这步很重要  
  169.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
  170.         glEnable(GL_DEPTH_TEST);  
  171.   
  172.         glUseProgram(gpuProgram.mProgram);  
  173.         //设置shader中变量的值  
  174.         glUniformMatrix4fv(gpuProgram.GetLocation("V"), 1, GL_FALSE, identity);  
  175.         glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));  
  176.         glUniform4fv(gpuProgram.GetLocation("U_AmbientLightColor"), 1, ambientLightColor);  
  177.         glUniform4fv(gpuProgram.GetLocation("U_AmbientMaterial"), 1, ambientMaterial);  
  178.         glUniform4fv(gpuProgram.GetLocation("U_DiffuseLightColor"), 1, diffuseLightColor);  
  179.         glUniform4fv(gpuProgram.GetLocation("U_DiffuseMaterial"), 1, diffuseMaterial);  
  180.         glUniform4fv(gpuProgram.GetLocation("U_SpecularLightColor"), 1, specularLightColor);  
  181.         glUniform4fv(gpuProgram.GetLocation("U_SpecularMaterial"), 1, specularMaterial);  
  182.         glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos);  
  183.         glUniform4fv(gpuProgram.GetLocation("U_LightDirection"), 1, spotLightDirection);  
  184.         glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity);  
  185.         //设置方向光光源的位置  
  186.         lightPos[0] = 0.0f;  
  187.         lightPos[1] = 1.5f;  
  188.         lightPos[2] = 0.0f;  
  189.         lightPos[3] = 0.0f;  
  190.         //漫反射光照强度  
  191.         diffuseIntensity = 1.0f;  
  192.         //聚光灯中心线和入射光线最大夹角  
  193.         spotLightCutoff = 0.0f;  
  194.         //设置shader中变量的值  
  195.         glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos);  
  196.         glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity);  
  197.         glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff);  
  198.         glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model1));  
  199.         glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix1));  
  200.         //绘制被方向光照射的立方体  
  201.         cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal"));  
  202.         cube.Draw();  
  203.         //设置点光源的位置  
  204.         lightPos[0] = 0.0f;  
  205.         lightPos[1] = 3.0f;  
  206.         lightPos[2] = -6.0f;  
  207.         lightPos[3] = 1.0f;  
  208.         diffuseIntensity = 3.0f;  
  209.         //设置shader中变量的值  
  210.         glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos);  
  211.         glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity);  
  212.         glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model2));  
  213.         glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix2));  
  214.         //绘制被点光源照射的立方体  
  215.         cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal"));  
  216.         cube.Draw();  
  217.         //设置聚光灯的位置  
  218.         lightPos[0] = 2.0f;  
  219.         lightPos[1] = 3.0f;  
  220.         lightPos[2] = -6.0f;  
  221.         lightPos[3] = 1.0f;  
  222.         diffuseIntensity = 4.0f;  
  223.         spotLightCutoff = 15.0f;//degree  
  224.         glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos);  
  225.         glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity);  
  226.         glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff);  
  227.         glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model3));  
  228.         glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix3));  
  229.         //绘制被聚光灯照射的立方体  
  230.         cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal"));  
  231.         cube.Draw();  
  232.         glUseProgram(0);  
  233.         glFlush();  
  234.         fbo.Unbind();  
  235.   
  236.   
  237.         glClearColor(0.1f, 0.4f, 0.7f, 1.0f);  
  238.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//这步很重要  
  239.         glUseProgram(fsqProgram.mProgram);  
  240.   
  241.         glActiveTexture(GL_TEXTURE0);  
  242.         //将fbo中的内容作为纹理  
  243.         glBindTexture(GL_TEXTURE_2D,fbo.GetBuffer("color"));  
  244.         glUniform1i(fsqProgram.GetLocation("U_MainTexture"), 0);  
  245.   
  246.         if (isFullScreen){ //分屏渲染  
  247.             fsq.DrawToLeftTop(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord"));  
  248.             fsq.DrawToLeftBottom(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord"));  
  249.             fsq.DrawToRightTop(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord"));  
  250.             fsq.DrawToRightBottom(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord"));  
  251.         }  
  252.         else //绘制一个充满屏幕的四边形  
  253.         {  
  254.             fsq.Draw(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord"));  
  255.         }  
  256.         glUseProgram(0);  
  257.         glFlush();  
  258.         SwapBuffers(dc);  
  259.     }  
  260.     return 0;  
  261. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值