I am unable to set viewport to desired dimensions. Despite specifying (1980 x 1080), the resultant dimensions are (1366 x 855). The 3D examples in pyqtgraph too do not show full screen and are located at lower left corner only.
import pyqtgraph.opengl as gl
from PyQt5 import QtWidgets
from pyqtgraph.Qt import QtCore
app = QtWidgets.QApplication([])
view = gl.GLViewWidget()
view.opts['viewport'] = (0, 0, 1920, 1080)
view.showMaximized()
view.setMaximumSize(1920, 1080)
print ("%d %d" % (view.height() , view.width()))
view.setWindowTitle('3D Matrix Visualization')
## create three grids, add each to the view
xgrid = gl.GLGridItem()
ygrid = gl.GLGridItem()
zgrid = gl.GLGridItem()
view.addItem(xgrid)
view.addItem(ygrid)
view.addItem(zgrid)
## rotate x and y grids to face the correct direction
xgrid.rotate(90, 0, 1, 0)
ygrid.rotate(90, 1, 0, 0)
## scale each grid differently
xgrid.scale(0.2, 0.1, 0.1)
ygrid.scale(0.2, 0.1, 0.1)
zgrid.scale(0.1, 0.2, 0.1)
If I run the code without changing viewport settings, the parent window, by the virtue of showMaximized(), appears full screen. But the drawable area is confined to 1/4 of the screen in the lower left corner.
view.opts['viewport'] = (0, 0, 1920, 1080)
Using above code, does make drawable area larger but then it is not large enough to cover maximized screen. It is 1366x855. The grid/axis appears in upper right corner and not in the center of 1366x855. In the default mode, the grid/axis appears in the center of the 1/4 drawable area.
Any help is appreciated.
GLViewWidget is a subclass of QtOpenGL.QGLWidget, as shown in PyQtGraph's Doc.
So, maybe we can use the view.setFixedSize(WidthOfParent, HeightOfParent) to adjust the size of viewport while resizing the parent widget.
For Mac with Retina display: The problem is probably that Mac is trying to use virtual resolution when doing high DPI scaling whereas pyqtgraph uses physical resolution.
It should have been fixed in the latest pyqtgraph github branch(link), but the latest PYPI version hasn't been updated since 2016, so please try pip installing directly from github as per official recommendation:
pip install git+https://github.com/pyqtgraph/pyqtgraph
Related
I'm creating a simple window manager for future projects and I seem to have run into a problem. I have a snippet of code which is supposed to change the viewport's position to the middle of the window whenever somebody resizes it, and it seems to work completely fine when changing position on the x-axis, as seen here. Unfortunately, it doesn't work on the y-axis, instead showing up at the bottom of the window. here is the code that handles this:
/* create viewport */
if (win->width > win->height)
glViewport((win->width / 2 - win->viewport.width / 2), 0, win->viewport.width, win->viewport.height);
else
/* FIXME: viewport appears at bottom of window, i have no idea why */
glViewport(0, (win->height / 2 - win->viewport.height / 2), win->viewport.width, win->viewport.height);
I have changed a number of variables in the equation but none of them yielded any results. I have ran the equation outside of glViewport and it returns the desired numbers. OpenGL is intentionally changing the viewports position to (0,0) and I have yet to figure out why. if it helps at all, I'm using OpenGL 3.3 and SDL2 on a Windows machine.
If anybody could tell me what I need to do to fix this, I would greatly appreciate it. Please and thank you.
I have run in a similar problem with SDL2 too.
I think the missing part is that you are not considering the aspect ractio value.
Also using SDL2 with Opengl you should consider that the drawable area can be different from the window area.
Assuming w and h the original sizes,
draw_w and _draw_h the current drawable area size,
view_w view_h the viewport area size,
we can calculate it as :
SDL_GL_GetDrawableSize(window,&draw_w,&draw_h);
float ratio = (float)w/(float)h;
if(draw_w/ratio < draw_h)
{
view_w = draw_w;
view_h = (int)((float)view_w/ratio);
}
else
{
view_h = draw_h;
view_w = (int)((float)view_h*ratio);
}
x = (draw_w-view_w)/2;
y = (draw_h-view_h)/2;
glViewport(x, y, view_w, view_h);
I have used a similar function applied to a SDL2 filter event as :
if(event->type==SDL_WINDOWEVENT && (event->window.event==SDL_WINDOWEVENT_SIZE_CHANGED || event->window.event==SDL_WINDOWEVENT_EXPOSED))
How can I programmatically set the white balance of an uEye USB camera (from the IDS manufacturer) to work with no automatic white balance and pre-defined multipliers when is_SetWhiteBalanceMultipliers() function is obsolete?
Some background: I work with a uEye USB2 camera (from IDS) connected to Linux machine. I need to get an RGB image with pre-defined colors (of cause on a pre-defined scene) from the camera. For example, I want to configure the WB to red 1.25 multiplier, green 1.0, and blue 2.0 multiplier.
For this task, I am using the uEye SDK on Linux (header file ueye.h).
The manual (A: Camera basics > Camera parameters) states that the is_SetWhiteBalanceMultipliers() function is obsolete and suggests to use is_SetAutoParameter() function instead. It was easy to disable the auto-white balance (is_SetAutoParameter( hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, 0, 0), but I struggle to find a way to configure the red/green/blue multipliers. The parameter IS_SET_AUTO_WB_OFFSET and IS_SET_AUTO_WB_GAIN_RANGE work only when the automatic white balance engaged and do nothing when it is disabled. I will be grateful for any suggestions!
I had the same issue. I think you can achieve the old result using the function "is_SetHardwareGain" on which you directly pass the main, red, green and blue gains. In my case I disabled the white balance before doing it just to make sure it works. In this example, I wanted to set the values to RGB gains = [8%, 0%, 32%] and the master gain to 0% (to not confuse with gain factors 0% normally corresponds to 1x gain factor):
double param1, param2; param1=0;
is_SetColorCorrection (hCam, IS_CCOR_DISABLE, ¶m1); //Disables the color fitler correction matrix
flagIDS = is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, ¶m1, ¶m2);
param1=WB_MODE_DISABLE;
flagIDS = is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_SENSOR_WHITEBALANCE, ¶m1, ¶m2);
flagIDS = is_SetHardwareGain (hCam, 0, 8, 0, 32);
So i'm playing around with creating a simple game engine in c++. I needed to render some text so I used this tutorial (http://learnopengl.com/#!In-Practice/Text-Rendering) for guidance. It's using the library freetype 2.
Everything works great, text is rendering as it should. But now when i'm fleshing the ui out and is creating labels I would like to be able to change the size of the text. I can do so by scaling the text, but I would like to be able to do so by using pixels.
Here you can see the scaling in action:
GLfloat xpos = x + ch.Bearing.x * scale;
GLfloat ypos = y + linegap + (font.Characters['H'].Bearing.y - ch.Bearing.y) * scale;
GLfloat w = ch.Size.x * scale;
GLfloat h = ch.Size.y * scale;
So in my method renderText I just pass a scale variable and it scales the text. But I would prefer to use pixels as it is more user friendly, is there any way I could do this in freetype 2 or am I stuck with a scale variable?
Assuming you don't want to regenerate the glyphs at a different resolution, but instead want to specify scale as a unit of pixels instead of a ratio (i.e. you want to say scale = 14 pixels instead of scale = 29%), then you can do the following: Save the height value you passed to FT_Set_Pixel_Sizes (which is 48 in the tutorial). Now if you want a 14-pixel render, just divide 14 by that number (48), so it would be scale = 14.0f / 48.0f. That will give you the scaling needed to render at a 14-pixel scale from a font that was originally generated with a 48-pixel height.
You might want to play with your OpenGL texture filters or mipmapping as well when you do this to improve your results. Additionally, fonts sometimes have low-resolution pixel hinting, which helps them be rendered clearly even at low resolutions; unfortunately this hinting information is lost/not used when you generate a high res texture and then scale it down to a smaller render size, so it might not look as clear as you desire.
I'm using bindings of OpenGL and glfw for Go on OS X 10.7, OpenGL version 3.x.
I enable GL_SCISSOR_TEST and set scissor rectangle to (0, 0, 1, 1). But it has absolutely no effect on the rendering -- the whole viewport is being updated.
Here's the code:
gl.Enable(gl.SCISSOR_TEST)
gl.Scissor(0, 0, 1, 1)
fmt.Printf("scissor enabled = %v\n", gl.IsEnabled(gl.SCISSOR_TEST))
box := make([]int32, 4)
gl.GetIntegerv(gl.SCISSOR_BOX, box)
fmt.Printf("scissor box = %v\n", box)
Console output:
scissor enabled = true
scissor box = [0 0 1 1]
I'm not sure what to make of this. The fact that glIsEnabled() and glGetIntegerv() both report correct values make me think that there is still some state missing that is necessary for activating the scissor test. I tried enabling GL_STENCIL_TEST and initializing glfw with 1 and 8 bits for stencil, still no effect, although glIsEnabled(GL_STENCIL_TEST) returns true.
Update: This only seems to be a problem at some computers. The normal, intuitive code seems to work fine one my home computer, but the computer at work has trouble.
Home computer: (no problems)
Windows XP Professional SP3
AMD Athlon 64 X2 3800+ Dual Core 2.0 GHz
NVIDIA GeForce 7800 GT
2 GB RAM
Work computer: (this question applies to this computer)
Windows XP Professional SP3
Intel Pentium 4 2.8 Ghz (dual core, I think)
Intel 82945G Express Chipset Family
1 GB RAM
Original post:
I'm trying to apply a very simple texture to a part of the screen using Psychtoolbox in Matlab with the following code:
win = Screen('OpenWindow', 0, 127); % open window and obtain window pointer
tex = Screen('MakeTexture', win, [255 0;0 255]); % get texture pointer
% draw texture. Args: command, window pointer, texture pointer, source
% (i.e. the entire 2x2 matrix), destination (a 100x100 square), rotation
% (none) and filtering (nearest neighbour)
Screen('DrawTexture', win, tex, [0 0 2 2], [100 100 200 200], 0, 0);
Screen('Flip', win); % flip the buffer so the texture is drawn
KbWait; % wait for keystroke
Screen('Close', win); % close screen
Now I would expect to see this (four equally sized squares):
But instead I get this (right and bottom sides are cut off and top left square is too large):
Obviously the destination rectangle is a lot bigger than the source rectangle, so the texture needs to be magnified. I would expect this to happen symmetrically like in the first picture and this is also what I need. Why is this not happening and what can I do about it?
I have also tried using [128 0 1152 1024] as a destination rectangle (as it's the square in the center of my screen). In this case, all sides are 1024, which makes each involved rectangle a power of 2. This does not help.
Increasing the size of the checkerboard results in a similar situation where the right- and bottommost sides are not showed correctly.
Like I said, I use Psychtoolbox, but I know that it uses OpenGL under the hood. I don't know much about OpenGL either, but maybe someone who does can help without knowing Matlab. I don't know.
Thanks for your time!
While I don't know much (read: any) Matlab, I do know that textures are very picky in openGL. Last I checked, openGL requires texture files to be square and of a power of two (i.e. 128 x 128, 256 x 256, 512 x 512).
If they aren't, openGL is supposed to pad the file with appropriate white pixels where they're needed to meet this condition, although it could be a crapshoot depending on which system you are running it on.
I suggest making sure that your checkerboard texture fits these requirements.
Also, I can't quite make sure from your code posted, but openGL expects you to map the corners of your texture to the corners of the object you are intending to texture.
Another bit of advice, maybe try a linear filter instead of nearest neighbor. It's heavier computationally, but results in a better image. This probably won't matter in the end.
While this help is not Matlab specific, hope it is useful.
Without knowing a lot about the Psychtoolbox, but having dealt with graphics and user interfaces a lot in MATLAB, the first thing I would try would be to fiddle with the fourth input to Screen (the "source" input). Try shifting each corner by half-pixel and whole-pixel values. For example, the first thing I would try would be:
Screen('DrawTexture', win, tex, [0 0 2.5 2.5], [100 100 200 200], 0, 0);
And if that didn't seem to do anything, I would next try:
Screen('DrawTexture', win, tex, [0 0 3 3], [100 100 200 200], 0, 0);
My reasoning for this advice: I've noticed sometimes that images or GUI controls in my figures can appear to be off by a pixel, which I can only speculate is some kind of round-off error when scaling or positioning them.
That's the best advice I can give. Hope it helps!