Skip to content

Window, Surface and Stuffs#116

Open
KSP0O wants to merge 6 commits into
MrPowerGamerBR:mainfrom
KSP0O:surface-window-and-stuffs
Open

Window, Surface and Stuffs#116
KSP0O wants to merge 6 commits into
MrPowerGamerBR:mainfrom
KSP0O:surface-window-and-stuffs

Conversation

@KSP0O
Copy link
Copy Markdown
Contributor

@KSP0O KSP0O commented May 13, 2026

Split DRAW_POST out of the main draw flow to fix Undertale border/surface rendering issues and align behavior with the decompiled yoyo runner.

Implement proper glfw window dimension handling (window_get_width/height + window_set_size).

Implement application_surface_enable and application_surface_draw_enable builtins to control application surface usage and auto-draw behavior.

image

@KSP0O KSP0O force-pushed the surface-window-and-stuffs branch from f9c218e to 602d951 Compare May 13, 2026 02:51
@Fancy2209
Copy link
Copy Markdown
Collaborator

Could you resolve conflicts and rebase on main?

@KSP0O KSP0O force-pushed the surface-window-and-stuffs branch from 602d951 to faf08e7 Compare May 14, 2026 15:55
@KSP0O KSP0O force-pushed the surface-window-and-stuffs branch from faf08e7 to 11f6f24 Compare May 14, 2026 16:24
@KSP0O
Copy link
Copy Markdown
Contributor Author

KSP0O commented May 14, 2026

Could you resolve conflicts and rebase on main?

Done, I think everything is set now.

@MrPowerGamerBR
Copy link
Copy Markdown
Owner

The Post-Draw order is incorrect

The Pre-Draw and Post-Draw events are part of the Draw Event category. However, unlike the other Draw events these draw directly to the display buffer, which will be the size of the combined screen space for all viewports currently visible, or the window size if only using one viewport or none at all.

The Post-Draw must be, conceptually, here

void GLCommon_letterboxBlit(GLuint fbo, int32_t fboWidth, int32_t fboHeight, int32_t gameW, int32_t gameH, int32_t windowW, int32_t windowH) {
    int32_t sx, sy, ex, ey;
    GLCommon_computeLetterbox(gameW, gameH, windowW, windowH, &sx, &sy, &ex, &ey);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    // Post Draw
    glBlitFramebuffer(0, 0, fboWidth, fboHeight, sx, sy, ex, ey, GL_COLOR_BUFFER_BIT, GL_NEAREST);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

For that it will require changing the vtable to split up both parts of the GLCommon_letterboxBlit (which is called on endFrame)

@MrPowerGamerBR
Copy link
Copy Markdown
Owner

MrPowerGamerBR commented May 14, 2026

For reference, here's how GameMaker-HTML5 does it

	this.PreDraw(r);
	//this.SetApplicationSurface();				
	this.DrawViews(r);	
	// Disable application_surface, and now render direct to the screen
	if (g_bUsingAppSurface) {
	    surface_reset_target();
	}
	//check surface stack is empty
	if (g_SurfaceStack.length != 0)
	{
	    yyError("Unbalanced surface stack. You MUST use surface_reset_target() for each set.");
	    return;
	}		
	this.PostDraw(r);
    this.DrawApplicationSurface(r);
	this.DrawGUI(r);
	this.DrawCursor(r);
	Graphics_Restore();
};

As a reference, here's the GLFW target

        Runner_drawViews(runner, gameW, gameH, displayScaleX, displayScaleY, debugShowCollisionMasks); // GM-HTML5 drawViews

        renderer->vtable->endFrame(renderer); // Bind Framebuffer + Draw Application Surface

...and while writing this (unrelated to this PR), I think the Draw GUI event is also out of order, it should be done after Post-Draw, after the application surface has been drawn, currently it is drawn on Runner_drawViews

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants