Author Topic: Window fullscreen problem.  (Read 9986 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Window fullscreen problem.
« on: January 25, 2008 »
I've adapted the source code that Rbraz posted to create a very small opengl initialisation, the program below (freebasic), draws a 3D starfield.

The program will compile fine, but there are problems when going fullscreen.
As long as your desktop is set at 1024 * 768 it will run with no problems, however, if your desktop is < 1024*768, the origin is wrong and the display is chopped off.

If your desktop resolution is>1024*768 then the window opens correctly but the viewport is the wrong size (too small) and at the bottom left of the screen.

Any ideas? :)

What stooopid thing have I done now?

Code: [Select]

        option explicit
        option static

'-------------------------------------
' Includes
'-------------------------------------

    #include "GL/gl.bi"
    #include "GL/glu.bi"
    #include "windows.bi"

    DIM SHARED AS BYTE W_FULLSCREEN =1 : ' 1 = FULLSCREEN
    DIM SHARED AS INTEGER W_XO =40      : ' X pos of window
    DIM SHARED AS INTEGER W_YO =40      : ' Y pos of window   
    DIM SHARED AS INTEGER W_XW =1024    : ' Width.
    DIM SHARED AS INTEGER W_YH =768    : ' Height.

    DIM SHARED pfd as PIXELFORMATDESCRIPTOR
    DIM SHARED hdc as hDC
    DECLARE SUB InitOGL()


    DIM SHARED AS INTEGER STARS=500
    DIM SHARED AS DOUBLE VVX(STARS)
    DIM SHARED AS DOUBLE VVY(STARS)
    DIM SHARED AS DOUBLE VVZ(STARS)

    DECLARE SUB STARINIT()
    DECLARE SUB STARFIELD()



    STARINIT()

DIM SHARED XR AS SINGLE : ' X ROTATION
DIM SHARED YR AS SINGLE : ' Y ROTATION
DIM SHARED ZR AS SINGLE : ' Z ROTATION
   

DIM D AS INTEGER
DIM SHARED AS DOUBLE GX,GY,GZ,TW,ZRR,XRR,YRR,RRR,delta,mm,fr

mm=timer

InitOGL()
'===============================================================================
' MAIN LOOP
'===============================================================================
WHILE((GetAsyncKeyState(VK_ESCAPE)<>-32767))


    glClear(GL_DEPTH_BUFFER_BIT + GL_COLOR_BUFFER_BIT )
   

    starfield()
    GLFLUSH()
   
        TW=TIMER
   
        fr=fr+1
        xr = xr +delta
yr = yr +delta
zr = zr +delta
       
if timer-mm>=.05 then
    delta=0.3/fr
    mm=timer
    fr=0
end if
SwapBuffers(hDC)
sleep 1


WEND

END



SUB STARFIELD
DIM A AS INTEGER

GLPUSHMATRIX
    glTranslatef(0, 0, -9)     
    glRotatef(XR, 1.0, 0.0, 0.0)
    glRotatef(YR, 0.0, 1.0, 0.0)
    glRotatef(ZR, 0.0, 0.0, 1.0)   
   
    glpointsize 1.5

    FOR A=0 TO STARS

    GLCOLOR3F 0.4,0.6,1.0
    GLBEGIN GL_POINTS
        GLVERTEX3F vvx(a),vvy(a),vvz(a)
    GLEND
   
    vvz(a)=vvz(a)+(delta*2)
    if vvz(a)>=20 then vvz(a)=vvz(a)-40
    NEXT

GLPOPMATRIX

GLPUSHMATRIX
        glTranslatef(0, 0, -12)

glbegin gl_lines
        GLCOLOR3F 0.6,0.6,1.0
        GLVERTEX3F -17.4,-9.8,0
        GLCOLOR3F 0.9,0.8,1.0
        GLVERTEX3F  17.4,-9.8,0

        GLVERTEX3F -17.4,9.8,0
        GLCOLOR3F 0.6,0.6,1.0
        GLVERTEX3F  17.4,9.8,0

glend

GLPOPMATRIX


END SUB


SUB STARINIT()

DIM A AS INTEGER

FOR A=0 TO STARS
    VVX(A)=(RND(1)*40)-20
    VVY(A)=(RND(1)*40)-20
    VVZ(A)=(RND(1)*40)-20
NEXT

END SUB


'===============================================================================
' Initialise OpenGL
'===============================================================================
sub InitOGL()

pfd.cColorBits = 32
    pfd.cDepthBits = 32
pfd.dwFlags    = PFD_SUPPORT_OPENGL + PFD_DOUBLEBUFFER
    IF W_FULLSCREEN=1 THEN hDC = GetDC(CreateWindow( "Edit", "BLAH!", WS_POPUP+WS_VISIBLE+WS_MAXIMIZE, 0 , 0 , 0 , 0, 0, 0, 0, 0))
    IF W_FULLSCREEN<>1 THEN hDC = GetDC(CreateWindow("Edit", "BLAH!", WS_POPUP+WS_VISIBLE+WS_BORDER,W_XO, W_YO, W_XW , W_YH, 0, 0, 0, 0))   
SetPixelFormat ( hDC, ChoosePixelFormat ( hDC, @pfd) , @pfd )
wglMakeCurrent ( hDC, wglCreateContext(hDC) )
    ShowCursor(FALSE)
   

    GLVIEWPORT 0, 0, W_XW, W_YH                          '' Reset The Current Viewport
GLMATRIXMODE GL_PROJECTION                          '' Select The Projection Matrix
GLLOADIDENTITY
   
    GLUPERSPECTIVE 90.0, W_XW / W_YH, 0.1, 100.0       '' Calculate The Aspect Ratio Of The Window
   
GLMATRIXMODE GL_MODELVIEW                           '' Select The Modelview Matrix
GLLOADIDENTITY                                      '' Reset The Modelview Matrix

GLSHADEMODEL GL_SMOOTH                              '' Enable Smooth Shading
GLCLEARCOLOR 0.0, 0.0, 0.0,0
GLCLEARDEPTH 1.0                                    '' Depth Buffer Setup
GLENABLE GL_DEPTH_TEST                              '' Enables Depth Testing
GLDEPTHFUNC GL_LEQUAL                               '' The Type Of Depth Testing To Do
GLHINT GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST    '' Really Nice Perspective Calculations


    GLHINT(GL_FOG_HINT,GL_NICEST)
    GLFOGF(GL_FOG_DENSITY,0.05)
    GLFOGF(GL_FOG_START,    13.0)
    GLFOGF(GL_FOG_END,     15.0)
    GLFOGI(GL_FOG_MODE,GL_EXP2)   
    GLENABLE (GL_FOG)
   
end sub

Shockwave ^ Codigos
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: Window fullscreen problem.
« Reply #1 on: January 25, 2008 »
I can't see and call to

glViewport(0, 0, width, height)

in your code.....
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Window fullscreen problem.
« Reply #2 on: January 25, 2008 »
It's there mate.

Code: [Select]

    GLVIEWPORT 0, 0, W_XW, W_YH                          '' Reset The Current Viewport
Shockwave ^ Codigos
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: Window fullscreen problem.
« Reply #3 on: January 25, 2008 »
oh sorry.. saw it now..


try to set your projection matrix at every refresh (after you clear the screen) to see if it fixes the problem. That's what I do all the time just in case the projection state is wrong at the beginning of the scene redrawal
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Window fullscreen problem.
« Reply #4 on: January 25, 2008 »
The problem seems to be that it's grabbing the resolution of the desktop for the viewport.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Window fullscreen problem.
« Reply #5 on: January 25, 2008 »
Bear in mind it's not really going fullscreen, it's just fitting a window to the full size of the desktop, whatever res that is (I think you realise that).  You need to be calling ChangeDisplaySettings() to really do that.

So W_XW and W_YH would need to be set to the desktop size, not the size YOU want to set.
In fullscreen mode you need to add
Code: [Select]
W_XW=GetSystemMetrics(SM_CXSCREEN)
W_YH=GetSystemMetrics(SM_CYSCREEN)
before you call glViewport.

Jim
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: Window fullscreen problem.
« Reply #6 on: January 25, 2008 »
or take the client rectangle of your window...

with this Win32 API:


   RECT   localBox;

   // get client box
   GetClientRect(hWnd,&localBox);

   glViewport(0, 0, width, height);

We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Window fullscreen problem.
« Reply #7 on: January 25, 2008 »
That seems to have fixed if Jim, thanks :) I would have been a long time trying to find that! I am also going to try the solution you posted too Stormbringer.

K++ for your help guys.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: Window fullscreen problem.
« Reply #8 on: January 25, 2008 »
thanks!

The way I do it is if in full screen mode, create a window of the screen size (without any borders), otherwise any size (if in desktop mode)

I always get the client rectangle and set the viewport to the client area's with & height... then it always works, whatever the screen resolution is
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Window fullscreen problem.
« Reply #9 on: January 28, 2008 »
why are you guys not trying to use "ChangeDisplaySettings" API, which is the best way i think for what you are looking for.
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Window fullscreen problem.
« Reply #10 on: January 28, 2008 »
It uses more bytez :)

I dunno, this started off as Shockwave's OpenGL adventure, but it's ended up getting mixed in with some very Windows-specific size-coding stuff.  Very demo-coder!

Jim
Challenge Trophies Won:

Offline WidowMaker [retired]

  • %010101
  • Atari ST
  • ***
  • Posts: 134
  • Karma: 21
  • %010101
    • View Profile
Re: Window fullscreen problem.
« Reply #11 on: January 28, 2008 »
The size elment is really interesting for me too.

I tried to use this framework Rbraz posted (It look a lot like Aulds) and I am now writing my first Crakctro in Opengl :P

Screenshot attached.

I will of course be releasing the source code here when I am done with it because I am using a lot of code from this great forum.


Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Window fullscreen problem.
« Reply #12 on: January 28, 2008 »
ok, size coding related, hehe...

@WIndowMaker:
sshot looks nice... the only thing i dont really like to much is the logo, because i find its hard to read ^^ anyway nice work and still looking forward. keep on ya nice work
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline WidowMaker [retired]

  • %010101
  • Atari ST
  • ***
  • Posts: 134
  • Karma: 21
  • %010101
    • View Profile
Re: Window fullscreen problem.
« Reply #13 on: January 28, 2008 »
Va!n, my nick is Widowmaker, not WINDOWmaker :P

Trust me, Illusionmaker's logo is nice, it is hard to see from the shot where it is rotating.


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Window fullscreen problem.
« Reply #14 on: January 28, 2008 »
Real cracktro feeling Widowmaker :) Looking forward to seeing it finished!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Window fullscreen problem.
« Reply #15 on: January 28, 2008 »
Btw logo seems very nicely done, Va!n, did you expand the thumbnail? It's quite easy to read for me.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Window fullscreen problem.
« Reply #16 on: January 28, 2008 »
@Wi(n)dowmaker without "n"  :P
sorry for wrong spelling... i thought all the time your name is spelled with a "n" *sorry*.
The love the art of the logo and finally i managed to read the name *grin*
good luck with the prod!
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Window fullscreen problem.
« Reply #17 on: January 28, 2008 »
Screeny looks very cool indeed. Like the blocky
scrolly - and it seems like there are some flying
cubes in the stafield, too.

Logo rocks also IMHO !
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Window fullscreen problem.
« Reply #18 on: January 28, 2008 »
very nice coding shockwave!

i really like the fact that your not leaning on freebasic for the window setup or buffer controll, infact seing as your not would'nt you be beter of coding in cpp/ogl as there is very little diffrence.

you probably already know this but if your doing it in freebasic you can set your ogl window up with the screen command and you dont need hdc's to flip the buffers.

i personally like the way you are doing things though! keep it up  :cheers:
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Window fullscreen problem.
« Reply #19 on: January 28, 2008 »
Cheers mate :)

I tried with FB's screen command, it made bigger exe's though, so I'll probably stick with this type of framework.
Shockwave ^ Codigos
Challenge Trophies Won: