issue with undocumented gl_qwh

21 views
Skip to first unread message

Raul Miller

unread,
Jun 5, 2026, 10:57:08 AMJun 5
to J Programming Forum
I am trying to understand the nature of the undocumented gl_qwh
instruction which I see used in the Help > Studio > Qt Demos... shader
source.

In that demo, it is being used to determine the aspect ratio of the screen.

Intuitively, from the name (and usage), I would imagine that it
provides the width and height of the current drawing surface.

However, if I use this width and height as the width and height in the
argument to glViewport, I find that it's not quite the full drawing
surface (there are some pixels in the top of the drawing region and
the right hand side of the drawing region which are not used to
display the image. (These wind up being "beyond" largest supported
coordinates on the window's x and y axis, which in opengl ranges from
_1 to 1)).

Also, looking at qtide implementation (which seems to be spread out
over lib/wd/gl2.h, lib/wd/gl2class.h, lib/wd/ogl2.h and
lib/wd/wd.cpp), I am baffled by some of the complexity - I am not sure
why it's written the way it is (which limits my ability to contribute
usefully on this topic).

Since knowing the screen dimensions of the drawing surface seems like
a useful bit of information, is there some other approach I should be
using to make that query?

Should I (or we) be asking additional questions about the qtopengl API?

Thanks,

--
Raul

Raul Miller

unread,
Jun 5, 2026, 11:58:23 PMJun 5
to J Programming Forum
Here's an attempt at illustrating the problem. I'm doing two things here. One, I am attempting to include arbitrary J code inline. I am attempting to override email linewrap, but I do not know if it will succeed. The other is I am attempting to illustrate the problem I am having with gl_qwh (which seems to report the size I requested for the window, but which does not seem to correspond with the size of my window's drawing surface).

Anyways, here it is (this is an almost complete port of the code from the "OpenGL Introduction" lab from J6.02). If you remove the NB. from within the gl3lab_g_paint implementation, I expect you would see an off-center rendering of the triangle:

require 'gl2 gles ide/qt/opengl'

coinsert 'jgl2 jgles qtopengl'


GL3LAB_WINDOW=: wd rplc&(' opengl ';' opengl version 4.1 ')^:('Darwin'-:UNAME) 0 : 0

pc gl3lab closeok;

minwh 300 300;cc g opengl flush;

)


gl3lab_run=: 3 : 0

wd GL3LAB_WINDOW

wd 'pshow'

OGL=: ".wd'qhwndc g' NB. perhaps unnecessary?

)


gl3lab_patch_version_issues=: 3 :0

NB. todo: search and replace to address any significant versioning issues.

y

)


GL3LAB_SHADER_VERTEX=: gl3lab_patch_version_issues 0 : 0

#version 410 core

in vec3 gl3lab_vertex;

in vec3 gl3lab_color;

out vec4 gl3lab_color_of_vertex;

void main(void){

gl_Position= vec4(gl3lab_vertex,1.0);

gl3lab_color_of_vertex= vec4(gl3lab_color,1.0);

}

)


GL3LAB_SHADER_FRAGMENT=: gl3lab_patch_version_issues 0 : 0

#version 410 core

in vec4 gl3lab_color_of_vertex;

out vec4 fragColor;

void main(void){

fragColor= gl3lab_color_of_vertex;

}

)


shaderprogram=: 0

gl3lab_g_initialize=: 3 : 0

shaderprogram=: 0

wglPROC''

'err prog'=. gl_makeprogram GL3LAB_SHADER_VERTEX; GL3LAB_SHADER_FRAGMENT

if. #err do. smoutput err return. end.

shaderprogram=: prog

)


gl3lab_g_paint=: gl3lab_default_paint=: 3 : 0

if. 0=shaderprogram do. return. end.

NB. glViewport 0 0,wh=: gl_qwh'' NB. https://docs.gl/gl3/glViewport

gl3lab_draw''

)


gl3lab_draw=: 3 : 0

glClearColor 0 0 1 0 NB. https://docs.gl/gl3/glClearColor

glClear GL_COLOR_BUFFER_BIT NB. https://docs.gl/gl3/glClear

glBegin GL_POLYGON NB. https://docs.gl/gl3/glBegin

glColor3d ?0 0 0 NB. https://docs.gl/gl3/glColor

glVertex3i 1,0,0 NB. https://docs.gl/gl3/glVertex

glVertex3i 0,1,0

glVertex3i _1,0,0

glEnd '' NB. https://docs.gl/gl3/glBegin

)


NB. press Ctrl+f to report frames/second

gl3lab_fctrl_fkey=: 3 : 0

start=. 6!:1''

for. i.100 do.

gl3lab_g_paint''

gl_paintx''

end.

time=. (6!:1'')-start

smoutput 'w h: ',(":gl_qwh''),' frames/sec: ',":100%time

)


gl3lab_run''



Thanks,

-- 
Raul

bill lam

unread,
Jun 6, 2026, 10:35:41 AMJun 6
to fo...@jsoftware.com
It had been a long time since I implemented gl2class.h.
This uses macro to implement similar function drawing on isigraph,
opengl and printer surface.
Using a OOP might a better approach, but it is very low priority.

IIRC gl_qwh returns the wh of the Qt opengl widget, and I don't know the detail.
> To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
>
Reply all
Reply to author
Forward
0 new messages