Align OpenGL textured integration baselines
This commit is contained in:
Binary file not shown.
@@ -8,4 +8,4 @@ out vec2 vTexcoord;
|
||||
void main() {
|
||||
gl_Position = aPosition;
|
||||
vTexcoord = aTexcoord;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
pipelineState.Apply();
|
||||
|
||||
OpenGLTexture texture;
|
||||
if (!texture.LoadFromFile("Res/Image/earth.png", true)) {
|
||||
if (!texture.LoadFromFile("Res/Image/earth.png")) {
|
||||
Log("[ERROR] Failed to load texture");
|
||||
return -1;
|
||||
}
|
||||
@@ -215,15 +215,17 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
commandList.Draw(PrimitiveType::TriangleStrip, 4, 0);
|
||||
|
||||
swapChain.Present(0, 0);
|
||||
frameCount++;
|
||||
|
||||
if (frameCount >= captureEndFrame) {
|
||||
RenderDocCapture::Get().EndCapture();
|
||||
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
|
||||
Log("[INFO] Capture complete - taking screenshot!");
|
||||
OpenGLScreenshot::Capture(device, swapChain, "quad.ppm");
|
||||
break;
|
||||
}
|
||||
|
||||
swapChain.Present(0, 0);
|
||||
|
||||
if (frameCount == captureStartFrame) {
|
||||
RenderDocCapture::Get().BeginCapture("OpenGL_Quad_Test");
|
||||
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
|
||||
@@ -231,9 +233,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
}
|
||||
}
|
||||
|
||||
Log("[INFO] Capture complete - taking screenshot!");
|
||||
OpenGLScreenshot::Capture(device, swapChain, "quad.ppm");
|
||||
|
||||
sampler.Shutdown();
|
||||
texture.Shutdown();
|
||||
vertexArray.Shutdown();
|
||||
@@ -249,4 +248,4 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
Log("[INFO] OpenGL Quad Test Finished");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -11,8 +11,7 @@ uniform mat4 gProjectionMatrix;
|
||||
|
||||
void main() {
|
||||
vec4 positionWS = gModelMatrix * aPosition;
|
||||
positionWS.x = -positionWS.x;
|
||||
vec4 positionVS = gViewMatrix * positionWS;
|
||||
gl_Position = gProjectionMatrix * positionVS;
|
||||
vTexcoord = vec2(aTexcoord.x, 1.0 - aTexcoord.y);
|
||||
}
|
||||
vTexcoord = aTexcoord;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "XCEngine/Debug/ConsoleLogSink.h"
|
||||
#include "XCEngine/Debug/RenderDocCapture.h"
|
||||
#include "XCEngine/Core/Containers/String.h"
|
||||
#include "XCEngine/Core/Math/Matrix4.h"
|
||||
#include "XCEngine/Core/Math/Vector3.h"
|
||||
|
||||
#pragma comment(lib, "opengl32.lib")
|
||||
|
||||
@@ -30,6 +32,7 @@
|
||||
using namespace XCEngine::RHI;
|
||||
using namespace XCEngine::Debug;
|
||||
using namespace XCEngine::Containers;
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
static const int gWidth = 1280;
|
||||
static const int gHeight = 720;
|
||||
@@ -52,30 +55,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
void IdentityMatrix(float* m) {
|
||||
memset(m, 0, 16 * sizeof(float));
|
||||
m[0] = m[5] = m[10] = m[15] = 1.0f;
|
||||
}
|
||||
|
||||
void TranslationMatrix(float* m, float x, float y, float z) {
|
||||
memset(m, 0, 16 * sizeof(float));
|
||||
m[0] = 1.0f; m[12] = x;
|
||||
m[5] = 1.0f; m[13] = y;
|
||||
m[10] = 1.0f; m[14] = z;
|
||||
m[15] = 1.0f;
|
||||
}
|
||||
|
||||
void PerspectiveMatrix(float* m, float fov, float aspect, float nearZ, float farZ) {
|
||||
memset(m, 0, 16 * sizeof(float));
|
||||
float tanHalfFov = tanf(fov / 2.0f);
|
||||
m[0] = 1.0f / (aspect * tanHalfFov); // m[0][0]
|
||||
m[5] = 1.0f / tanHalfFov; // m[1][1]
|
||||
m[10] = -(farZ + nearZ) / (farZ - nearZ); // m[2][2]
|
||||
m[14] = -(2.0f * farZ * nearZ) / (farZ - nearZ); // m[2][3]
|
||||
m[15] = 0.0f;
|
||||
m[11] = -1.0f; // m[3][2] = -1 for OpenGL clip space
|
||||
}
|
||||
|
||||
struct Vertex {
|
||||
float pos[4];
|
||||
float texcoord[2];
|
||||
@@ -235,24 +214,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
}
|
||||
Log("[INFO] Shaders compiled successfully");
|
||||
|
||||
float modelMatrix[16];
|
||||
float viewMatrix[16];
|
||||
float projectionMatrix[16];
|
||||
|
||||
IdentityMatrix(viewMatrix);
|
||||
TranslationMatrix(modelMatrix, 0.0f, 0.0f, -5.0f);
|
||||
float aspect = 1280.0f / 720.0f;
|
||||
PerspectiveMatrix(projectionMatrix, 45.0f * 3.14159265f / 180.0f, aspect, 0.1f, 1000.0f);
|
||||
const float aspect = 1280.0f / 720.0f;
|
||||
const Matrix4x4 projectionMatrix = Matrix4x4::Perspective(45.0f * 3.141592f / 180.0f, aspect, 0.1f, 1000.0f);
|
||||
const Matrix4x4 viewMatrix = Matrix4x4::Identity();
|
||||
const Matrix4x4 modelMatrix = Matrix4x4::Translation(Vector3(0.0f, 0.0f, 5.0f));
|
||||
const Matrix4x4 projectionMatrixT = projectionMatrix.Transpose();
|
||||
const Matrix4x4 viewMatrixT = viewMatrix.Transpose();
|
||||
const Matrix4x4 modelMatrixT = modelMatrix.Transpose();
|
||||
|
||||
Log("[DEBUG] ProjectionMatrix:");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
||||
projectionMatrix[i*4], projectionMatrix[i*4+1], projectionMatrix[i*4+2], projectionMatrix[i*4+3]);
|
||||
projectionMatrixT.m[i][0], projectionMatrixT.m[i][1], projectionMatrixT.m[i][2], projectionMatrixT.m[i][3]);
|
||||
}
|
||||
Log("[DEBUG] ModelMatrix:");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
||||
modelMatrix[i*4], modelMatrix[i*4+1], modelMatrix[i*4+2], modelMatrix[i*4+3]);
|
||||
modelMatrixT.m[i][0], modelMatrixT.m[i][1], modelMatrixT.m[i][2], modelMatrixT.m[i][3]);
|
||||
}
|
||||
|
||||
OpenGLPipelineState pipelineState;
|
||||
@@ -278,12 +256,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
int projLoc = shader.GetUniformLocation("gProjectionMatrix");
|
||||
Log("[DEBUG] Uniform locations - gModelMatrix: %d, gViewMatrix: %d, gProjectionMatrix: %d", modelLoc, viewLoc, projLoc);
|
||||
commandList.SetShader(&shader);
|
||||
commandList.SetUniformMat4("gModelMatrix", modelMatrix);
|
||||
commandList.SetUniformMat4("gViewMatrix", viewMatrix);
|
||||
commandList.SetUniformMat4("gProjectionMatrix", projectionMatrix);
|
||||
commandList.SetUniformMat4("gModelMatrix", &modelMatrixT.m[0][0]);
|
||||
commandList.SetUniformMat4("gViewMatrix", &viewMatrixT.m[0][0]);
|
||||
commandList.SetUniformMat4("gProjectionMatrix", &projectionMatrixT.m[0][0]);
|
||||
|
||||
OpenGLTexture texture;
|
||||
if (!texture.LoadFromFile("Res/Image/earth.png", true)) {
|
||||
if (!texture.LoadFromFile("Res/Image/earth.png")) {
|
||||
Log("[ERROR] Failed to load texture");
|
||||
return -1;
|
||||
}
|
||||
@@ -340,15 +318,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
commandList.DrawIndexed(PrimitiveType::Triangles, (uint32_t)indices.size(), 0, 0);
|
||||
|
||||
swapChain.Present(0, 0);
|
||||
frameCount++;
|
||||
|
||||
if (frameCount >= captureEndFrame) {
|
||||
RenderDocCapture::Get().EndCapture();
|
||||
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
|
||||
Log("[INFO] Rendered %d frames (capture was %d-%d)", renderCount, captureStartFrame, captureEndFrame);
|
||||
Log("[INFO] Capture complete - taking screenshot!");
|
||||
|
||||
char exePath[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, exePath, MAX_PATH);
|
||||
char* lastSlash = strrchr(exePath, '\\');
|
||||
if (lastSlash) *lastSlash = '\0';
|
||||
strcat_s(exePath, "\\sphere.ppm");
|
||||
OpenGLScreenshot::Capture(device, swapChain, exePath);
|
||||
break;
|
||||
}
|
||||
|
||||
swapChain.Present(0, 0);
|
||||
|
||||
if (frameCount == captureStartFrame) {
|
||||
RenderDocCapture::Get().BeginCapture("OpenGL_Sphere_Test");
|
||||
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
|
||||
@@ -356,16 +343,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
}
|
||||
}
|
||||
|
||||
Log("[INFO] Rendered %d frames (capture was %d-%d)", renderCount, captureStartFrame, captureEndFrame);
|
||||
Log("[INFO] Capture complete - taking screenshot!");
|
||||
|
||||
char exePath[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, exePath, MAX_PATH);
|
||||
char* lastSlash = strrchr(exePath, '\\');
|
||||
if (lastSlash) *lastSlash = '\0';
|
||||
strcat_s(exePath, "\\sphere.ppm");
|
||||
OpenGLScreenshot::Capture(device, swapChain, exePath);
|
||||
|
||||
sampler.Shutdown();
|
||||
texture.Shutdown();
|
||||
indexBuffer.Shutdown();
|
||||
@@ -382,4 +359,4 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
Log("[INFO] OpenGL Sphere Test Finished");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user