opengl window and vbo vertexes

Started by
13 comments, last by Brother Bob 11 years, 3 months ago

I see a problem:

if i use a glViewport(0, 0, 1920, 1080); that is my full resolution screen all works fine, but if i use a 800 x 600 glViewport(0, 0, 800, 600); the triangle is an half of the correct rectangle that must occupy the half of the screen.
Then the error may be in the creation of the window?
this is my window's creation code:

HWND CreateAppWindow(const WNDCLASSEX &wcl, const char *pszTitle)
{
// Create a window that is centered on the desktop. It's exactly 1/4 the
// size of the desktop. Don't allow it to be resized.
int n = 0;
DWORD wndExStyle = WS_EX_OVERLAPPEDWINDOW;
DWORD wndStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
WS_MINIMIZEBOX | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

HWND hWnd = CreateWindowEx
(wndExStyle, wcl.lpszClassName, "title",
wndStyle, 0, 0, 1920, 1080, 0, 0, wcl.hInstance, 0);

if (hWnd)
{
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int halfScreenWidth = screenWidth / 2;
int halfScreenHeight = screenHeight / 2;
int left = (screenWidth - halfScreenWidth) / 2;
int top = (screenHeight - halfScreenHeight) / 2;
RECT rc = {0};

SetRect(&rc, left, top, left + halfScreenWidth, top + halfScreenHeight);
AdjustWindowRectEx(&rc, wndStyle, FALSE, wndExStyle);
MoveWindow(hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);

GetClientRect(hWnd, &rc);
m_windowWidth = rc.right - rc.left;
m_windowHeight = rc.bottom - rc.top;
}

return hWnd;
};

Advertisement

also if i set this

HWND hWnd = CreateWindowEx
(wndExStyle, wcl.lpszClassName, "title",
wndStyle, 0, 0, 1920, 1080, 0, 0, wcl.hInstance, 0);

to

HWND hWnd = CreateWindowEx
(wndExStyle, wcl.lpszClassName, "title",
wndStyle, 0, 0, 800, 600, 0, 0, wcl.hInstance, 0);

if i set the viewport to 1920w 1080h all work fine.

what can be'

As I said in my first post, your triangle is drawn in the viewport, not in the window. If you have a 1920x1080 window and set the viewport to the bottom-left 800x600 region, then the triangle will be drawn to that bottom-left 800x600 region of the whole 1920x1080 window. If you want the viewport to cover the whole window, then the viewport shall have the same size as the window.

then the vbo points are related to the viewport, is correct?

If so

1)i can create a window of 400 x 400

2)set this vbo :


-1, -1, 0,
-1, 1, 0,
1,1, 0,


3)set the ortho matrix with glm(m_MP = glm::ortho<GLfloat>(-1, 1, -1, 1); to


{1, 0, 0, 0}
{0, 1, 0, 0}
{0, 0, -1, 0}
{-0, -0, 0, 1}

4)all works fine.

but if:

1)ok,

2)set this vbo


0, 0, 0,
0,400,0
400,400,0

3)the ortho matrix sended to the shader as a mvp(now i change the name) is :


{0.0049999999, 0, 0, 0}
{0, 0.0049999999, 0, 0}
{0, 0, -1, 0}
{-1, -1, 0, 1}

but,i see nothing

this is all that i change , from the first to the second i change only the ortho projection and the vbo points from -1 1 to 0 400 ecc....

thanks again for your help, and sorry if i 'm a newbe

and the mview matrix is to use? i suppose that is identity .

by.

Start with the case that works and slowly change the numbers towards the case that doesn't work. You will hopefully see where the triangle goes and why it doesn't show up.

This topic is closed to new replies.

Advertisement