OpenGL: Fix screenshot gray edge issue by correcting SetWindowPos usage
- OpenGLSwapChain::Initialize now uses AdjustWindowRect before SetWindowPos - This ensures window client area matches expected size (1280x720) - Previously SetWindowPos was given client area size instead of full window size - Removed debug fprintf statements from OpenGLDevice - Updated minimal integration test to use cleaner code
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <windows.h>
|
||||
@@ -35,7 +37,12 @@ void SaveScreenshotPPM(const char* filename, int width, int height) {
|
||||
return;
|
||||
}
|
||||
|
||||
glFinish();
|
||||
glReadBuffer(GL_BACK);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
||||
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
|
||||
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
FILE* f = fopen(filename, "wb");
|
||||
@@ -101,23 +108,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
NULL, NULL, hInstance, NULL
|
||||
);
|
||||
|
||||
RECT clientRect;
|
||||
GetClientRect(hwnd, &clientRect);
|
||||
fprintf(stderr, "[minimal] Window client area: %ldx%ld\n", clientRect.right, clientRect.bottom);
|
||||
|
||||
if (!hwnd) {
|
||||
Log("[ERROR] Failed to create window");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OpenGLDevice device;
|
||||
fprintf(stderr, "[minimal] About to call InitializeWithExistingWindow\n");
|
||||
if (!device.InitializeWithExistingWindow(hwnd)) {
|
||||
fprintf(stderr, "[minimal] InitializeWithExistingWindow returned false\n");
|
||||
Log("[ERROR] Failed to initialize OpenGL device");
|
||||
return -1;
|
||||
}
|
||||
fprintf(stderr, "[minimal] InitializeWithExistingWindow succeeded\n");
|
||||
|
||||
ShowWindow(hwnd, nShowCmd);
|
||||
UpdateWindow(hwnd);
|
||||
@@ -132,7 +132,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
int frameCount = 0;
|
||||
const int targetFrameCount = 30;
|
||||
|
||||
while (true) {
|
||||
while (frameCount < targetFrameCount) {
|
||||
if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
if (msg.message == WM_QUIT) {
|
||||
break;
|
||||
@@ -145,19 +145,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
swapChain.Present(0, 0);
|
||||
frameCount++;
|
||||
|
||||
if (frameCount >= targetFrameCount) {
|
||||
Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
|
||||
SaveScreenshotPPM("minimal.ppm", gWidth, gHeight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
|
||||
SaveScreenshotPPM("minimal.ppm", gWidth, gHeight);
|
||||
|
||||
swapChain.Shutdown();
|
||||
device.Shutdown();
|
||||
Logger::Get().Shutdown();
|
||||
|
||||
Log("[INFO] OpenGL Integration Test Finished");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user