PDA

View Full Version : OpenGL and DirectX together?



kryton9
14-03-2007, 06:33
Guys, I was wondering, while you have an openGL window open with tbgl, can you also open a DirectX window?
Why would I do this?

Well DirectX has some interesting demos with controls and I thought I would experiment with those and see if I could make a module in c++ to use them?

I will tinker with it and get started tonight and see what happens. But if you know the answer please let me know, as I won't be finished tonight. Thanks.

kryton9
14-03-2007, 06:47
Ok, I did a very simple test. I compiled a release version of the demo from the directX sdk in an executeable.

I ran TopDown in full screen. I alt tabbed out to the folder where the dirextX executeable is at and ran it. They both ran fine.
Both windows were updating. I even took the directX window to full screen and they both worked.

So that was a very pleasant surprise and lots to think about now :)

Michael Hartlef
14-03-2007, 07:58
Why would someone lie to do this. Makes no sence to me. Both are graphic APIs, both can basically do the same. So which purpose?

kryton9
14-03-2007, 10:00
Mike, hehehehe, I know it is crazy, but it is nice to know we can mix and match the 2. Just for a simple example, they have a really nice user interface that can sit on the graphics window. So for working on the options for our game, it can look cool and non windows like and still feel like it is part of the game.

I will try to work on a mock up as my challenge to learn it better. Hope to have something to show in a few days.

Michael Hartlef
14-03-2007, 10:34
What do you mean with DX has a user interface? Usually you build this with sprites/quads/text and handle everything by code, means a UI is nothing more than graphics on top of a game scene. Is this a new DX10 feature?

kryton9
14-03-2007, 10:37
No, I am running directX 9.
Here is where it is located on my computer and I just did the standard install:
C:\Program Files\Microsoft DirectX SDK (August 2006)\Samples\C++\Direct3D\CustomUI

Michael Hartlef
14-03-2007, 10:52
Good luck with your ventures.

Michael Hartlef
14-03-2007, 10:53
Questions, why don't you try to create some gui routines with TBGL?

kryton9
14-03-2007, 21:01
Mike, I am lazy... plus just an excuse to try it out to learn.

Petr Schreiber
14-03-2007, 22:16
Hi kryton,

GUI should be quite easy now in TBGL with new functionalities.
I will think about some simple sample :)


Bye,
Petr

kryton9
15-03-2007, 03:00
Thanks Petr, will be nice to see what clever approach you come up with!!

Petr Schreiber
15-03-2007, 21:24
Thanks Petr, will be nice to see what clever approach you come up with!!


Hehe, I am also curious :)
I have idea for trackbar, button and checkbox, this should be quite easy stuff.


Bye,
Petr

kryton9
15-03-2007, 21:29
Glad to see those talented brain cells are working and you have ideas already!

Petr Schreiber
16-03-2007, 19:37
Hi Kent,

I am very sorry, but I am quite busy.
So I created just extremely basic version of trackbars for you.

I need more time to think how to do it better :)



'
' TBGL Quick Trackbar
'
#minversion 1.3.0.0
Uses "TBGL"
Uses "UI"

Dim hWnd As Dword

hWnd = TBGL_CreateWindowEx("Drag track bar sliders / click on bars to create color - press ESC to quit", 640, 480, 32, 0)
TBGL_ShowWindow

TBGL_GetAsyncKeyState(-1) ' Resets ESC key status before checking

type tTrackBar
pX as single
pY as single

sX as single
sY as single

vMin as single
vMax as single
vCur as single
end type

dim TrackBarR, TrackBarG, TrackBarB as tTrackBar
dim R, G, B as long = 128

TrackBar_New(TrackBarR, -0.62, 0.7, 0.75, 0.06, 0, 255, 128 )
TrackBar_New(TrackBarG, -0.62, 0.5, 0.75, 0.06, 0, 255, 128 )
TrackBar_New(TrackBarB, -0.62, 0.3, 0.75, 0.06, 0, 255, 128 )

tbgl_Uselighting 1
tbgl_UselightSource %GL_LIGHT0, 1
tbgl_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_POSITION, 5,2,3,1
tbgl_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_AMBIENT, 0.3,0.3,0.3,1


DIM hFont AS DWORD = Font_Create("Courier New", 12)
TBGL_BuildFont hFont

While TBGL_IsWindow(hWnd)

tbgl_ClearFrame

' Render of scene
tbgl_Camera -5,5,5,0,0,0

tbgl_Color R, G, B
tbgl_PushMatrix
tbgl_Rotate GetTickCount/10,1,1,1
tbgl_TORUS 0.2,2.0
tbgl_Rotate GetTickCount/10,1,1,1
tbgl_TORUS 0.2,2.0
tbgl_Rotate GetTickCount/10,1,1,1
tbgl_TORUS 0.2,2.0
tbgl_PopMatrix

' GUI part
tbgl_resetMatrix

' The trackbar "beam" is not "color protected" so we can set it from here
' I did not put the tbgl_color R,0,0 for example, beause for 0 it would be black :)
tbgl_Color 127+R/2,0,0
TrackBar_Render(TrackBarR, R)
tbgl_Color 0,127+G/2,0
TrackBar_Render(TrackBarG, G)
tbgl_Color 0,0,127+B/2
TrackBar_Render(TrackBarB, B)

tbgl_DrawFrame

If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While

Wend

tbgl_killFont
TBGL_DestroyWindow

' Creates new trackbar / fills structire with data
sub TrackBar_New( byref trkBar as tTrackBar, posX as single, posY as single, sizeX as single, sizeY as single, valMin as single, valMax as single, valCur as single )

trkBar.px = posX
trkBar.py = posY

trkBar.sx = sizeX
trkBar.sy = sizeY

trkBar.vMin = valMin
trkBar.vMax = valMax
trkBar.vCur = valCur

end sub

' renders trackbar and returns value to variable
sub TrackBar_Render( trkBar as tTrackBar, byref valToSet as single )

local position as single
local x, y, z as single

tbgl_PushMatrix
tbgl_Translate trkBar.px, trkBar.py, -2
tbgl_Box trkBar.sx, trkBar.sy, trkBar.sy
tbgl_PopMatrix

tbgl_GetPixelinfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, x, y, z

if tbgl_PointInside3D( x, y, z, %TBGL_OBJ_CUBE3, trkBar.px, trkBar.py, -2, trkBar.sx, trkBar.sy/2, 0.1 ) then

tbgl_UseDepth 0
tbgl_Uselighting 0

position = trkBar.vMin + between(x, trkBar.px-trkBar.sx/2, trkBar.px+trkBar.sx/2)/100 * (trkBar.vMax - trkBar.vMin)

if tbgl_MouseGetLbutton then
trkBar.vCur = position
valToSet = round(trkBar.vCur, 2)
tbgl_Color 255,255,255
tbgl_PrintFont format$(valToSet, "#.00"), x+0.025, y+0.01, z
else
tbgl_Color 255,255,255
tbgl_PrintFont format$(valToSet, "#.00"), trkBar.px+trkBar.sx/2+0.025, trkBar.py, z
end if

tbgl_Uselighting 1
tbgl_UseDepth 1

end if

tbgl_PushMatrix
tbgl_Color 255,255,255
tbgl_Translate (trkBar.px-trkBar.sx/2) + trkBar.vCur / (trkBar.vMax - trkBar.vMin)*trkBar.sx, trkBar.py, -2
tbgl_Box trkBar.sx/(trkBar.vMax-trkBar.vMin)*2, trkBar.sy+0.01, trkBar.sy*1.1
tbgl_PopMatrix

end sub



Bye,
Petr

ErosOlmi
16-03-2007, 21:48
What a nice example !!!

Michael Hartlef
16-03-2007, 22:12
I second that. :)

kryton9
17-03-2007, 00:00
Thanks Petr, a very nice example. I appreciate you putting it together when so busy!