Browse Source

多重采样抗锯齿

master
blobt 4 years ago
parent
commit
1d8c5f079e
  1. BIN
      .vs/shader2/v14/.suo
  2. 62
      main.cpp
  3. 6
      res/shader/RenderDepthBuffer.fs
  4. 1454
      wglew.h

BIN
.vs/shader2/v14/.suo

62
main.cpp

@ -1,5 +1,6 @@
#include <windows.h> #include <windows.h>
#include "glew.h" #include "glew.h"
#include "wglew.h"
#include "Glm/glm.hpp" #include "Glm/glm.hpp"
#include "Glm/ext.hpp" #include "Glm/ext.hpp"
#include <stdio.h> #include <stdio.h>
@ -10,6 +11,44 @@
#pragma comment(lib,"opengl32.lib") #pragma comment(lib,"opengl32.lib")
#pragma comment(lib, "glew32.lib") #pragma comment(lib, "glew32.lib")
HGLRC CreateNBRC(HDC dc)
{
HGLRC rc;
GLint attribs[]{
WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
WGL_RED_BITS_ARB,8,
WGL_GREEN_BITS_ARB,8,
WGL_BLUE_BITS_ARB,8,
WGL_ALPHA_BITS_ARB,8,
WGL_DEPTH_BITS_ARB,24,
WGL_STENCIL_BITS_ARB,8,
WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
WGL_SAMPLES_ARB,16,
NULL,NULL
};
int pixelFormat[256] = { 0 };
UINT formatNum = 0;
wglChoosePixelFormatARB(dc, attribs, NULL, 256, pixelFormat, &formatNum);
printf("support format number is %u\n", formatNum);
if (formatNum>0)
{
PIXELFORMATDESCRIPTOR pfd;
DescribePixelFormat(dc, pixelFormat[0], sizeof(pfd), &pfd);
SetPixelFormat(dc, pixelFormat[0], &pfd);
int contexAttributes[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB,4,
WGL_CONTEXT_MINOR_VERSION_ARB,3,
WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
rc = wglCreateContextAttribsARB(dc, nullptr, contexAttributes);
}
return rc;
}
/** /**
* @hwnd * @hwnd
* @msg * @msg
@ -90,6 +129,22 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
/*glew初始化*/ /*glew初始化*/
glewInit(); glewInit();
if (wglChoosePixelFormatARB)
{
//destroy window
wglMakeCurrent(dc, nullptr);
wglDeleteContext(rc);
rc = nullptr;
ReleaseDC(hwnd, dc);
dc = nullptr;
DestroyWindow(hwnd);
hwnd = CreateWindowEx(NULL, L"GLWindow", L"OpenGL Window", WS_OVERLAPPEDWINDOW, 100, 100, windowWidth, windowHeight, NULL, NULL, hinstance, NULL);
//create msaa rc
dc = GetDC(hwnd);
rc = CreateNBRC(dc);
wglMakeCurrent(dc, rc);
}
/*创建program*/ /*创建program*/
GLuint program = CreateGPUProgram("res/shader/SimpleTexture.vs", "res/shader/SimpleTexture.fs"); GLuint program = CreateGPUProgram("res/shader/SimpleTexture.vs", "res/shader/SimpleTexture.fs");
@ -224,7 +279,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
glUseProgram(fsqprogram); glUseProgram(fsqprogram);
glBindVertexArray(fsqvao); glBindVertexArray(fsqvao);
glBindTexture(GL_TEXTURE_2D, depthBuffer);
glBindTexture(GL_TEXTURE_2D, colorBuffer);
glUniform1i(fsqtextureLocation, 0); glUniform1i(fsqtextureLocation, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fsqibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fsqibo);
glDrawElements(GL_TRIANGLES, fsqindexCount, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, fsqindexCount, GL_UNSIGNED_INT, 0);
@ -247,13 +302,8 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
DispatchMessage(&msg); DispatchMessage(&msg);
} }
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
what(); what();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
RenderFullScreenQuad();
glFlush(); glFlush();
SwapBuffers(dc); SwapBuffers(dc);

6
res/shader/RenderDepthBuffer.fs

@ -4,6 +4,8 @@ varying vec2 V_Texcoord;
void main() void main()
{ {
float depthValue=pow(texture2D(U_MainTexture,V_Texcoord).r,8.0);
gl_FragColor=vec4(vec3(depthValue),1.0);
//float depthValue=pow(texture2D(U_MainTexture,V_Texcoord).r,8.0);
//gl_FragColor=vec4(vec3(depthValue),1.0);
gl_FragColor=texture2D(U_MainTexture,V_Texcoord);
} }

1454
wglew.h
File diff suppressed because it is too large
View File

Loading…
Cancel
Save