Jump to content

  • Log In with Google      Sign In   
  • Create Account

Moving from Direct3D to OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 VitaliBR   Members   -  Reputation: 147

Like
0Likes
Like

Posted 16 August 2012 - 08:33 AM

Hi! :)

I'm learning OpenGL, (always programmed to direct3d).
I chose the Direct3D rendering options this way:

_d3d = Direct3DCreate9(D3D_SDK_VERSION);
bool p_bMultiSample = true;
bool p_bSuperSample = true;
bool bHW = true;
D3DDEVTYPE eType = bHW ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF;
// get the current display mode
D3DDISPLAYMODE sMode;
_d3d->GetAdapterDisplayMode(0,&sMode);
    D3DPRESENT_PARAMETERS d3dpp;
RECT rect;
GetClientRect( hwnd , &rect );
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = !fullscreen;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow = hwnd;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferWidth = rect.right - rect.left; //screenWidth;
    d3dpp.BackBufferHeight = rect.bottom - rect.top; //screenHeight;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.BackBufferCount = 1;
// check whether we can use a D32 depth buffer format
if ( SUCCEEDED ( _d3d->CheckDepthStencilMatch(0,eType,
  D3DFMT_X8R8G8B8,D3DFMT_X8R8G8B8,D3DFMT_D32)))
{
  d3dpp.AutoDepthStencilFormat = D3DFMT_D32;
}
else
{
  d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;
}
// find the highest multisample type available on this device
D3DMULTISAMPLE_TYPE sMS = D3DMULTISAMPLE_2_SAMPLES;
D3DMULTISAMPLE_TYPE sMSOut = D3DMULTISAMPLE_NONE;
DWORD dwQuality = 0;
if (p_bMultiSample)
{
  while ((D3DMULTISAMPLE_TYPE)(D3DMULTISAMPLE_16_SAMPLES + 1)  !=
   (sMS = (D3DMULTISAMPLE_TYPE)(sMS + 1)))
  {
   if(SUCCEEDED( _d3d->CheckDeviceMultiSampleType(0,eType,
    sMode.Format,TRUE,sMS,&dwQuality)))
   {
    sMSOut = sMS;
   }
  }
  if (0 != dwQuality)dwQuality -= 1;

  d3dpp.MultiSampleQuality = dwQuality;
  d3dpp.MultiSampleType = sMSOut;
}
// preget the device capabilities. If the hardware vertex shader is too old, we prefer software vertex processing
D3DCAPS9 g_sCaps;
_d3d->GetDeviceCaps( 0, eType, &g_sCaps);
DWORD creationFlags = D3DCREATE_MULTITHREADED;
if( g_sCaps.VertexShaderVersion >= D3DVS_VERSION( 2, 0))
  creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
  creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
////////////////////////////////////////////////////////////////////////////////////
    // create a device class using this information and the info from the d3dpp stuct
////////////////////////////////////////////////////////////////////////////////
    _d3d->CreateDevice(D3DADAPTER_DEFAULT,
					  eType,
					  hwnd,
					  creationFlags,
					  &d3dpp,
					  &_d3ddev);

In OpenGL I only got this far:
#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE  0x809D
#endif

// Initialize OpenGL
void VS_Core::initGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor (backR,backG,backB, 0.0);
    glEnable(GL_CULL_FACE);
    glEnable(GL_MULTISAMPLE);
    //QMessageBox::about( this, tr("OpenGL Version"), tr((char*)glGetString(GL_VERSION)));
    qDebug((char*)glGetString(GL_VERSION));
    qDebug((char*)glGetString(GL_RENDERER));
    /*
	    GLint bufs;
	    GLint samples;
	    glGetIntegerv(GL_SAMPLE_BUFFERS, &bufs);
	    glGetIntegerv(GL_SAMPLES, &samples);
	    qDebug("Have %d buffers and %d samples", bufs, samples);
    */
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_COLOR_MATERIAL);
    glDisable(GL_CULL_FACE);
    glEnable(GL_TEXTURE_2D);
}


Sponsor:

#2 larspensjo   Members   -  Reputation: 1557

Like
3Likes
Like

Posted 16 August 2012 - 10:31 AM

glClearColor states what color to use when you clear, so you should call it before glClear.

I would recommend having a look at Learning Modern 3D Graphics Programming. You can browse quickly through the parts you already understand, and quickly get to know how it is done the OpenGL way.

One problem is that Windows only support a very old API to OpenGL (1.1 or something like that), but the device drivers provides full support. To get access to the full functionality, you either have to use a special function to get the address of the extended functions, or you use a library that has it all prepared. I would recommend GLEW for this. I have heard gl3w is also good, but haven't used it myself.

If you want to write code that is compatible with Linux and other platforms, I would recommend glfw for a minimal library that provides an interface to windows management and other input and output devices. Stay away from GLUT.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#3 VitaliBR   Members   -  Reputation: 147

Like
1Likes
Like

Posted 16 August 2012 - 11:32 AM

glClearColor states what color to use when you clear, so you should call it before glClear.

I would recommend having a look at Learning Modern 3D Graphics Programming. You can browse quickly through the parts you already understand, and quickly get to know how it is done the OpenGL way.

One problem is that Windows only support a very old API to OpenGL (1.1 or something like that), but the device drivers provides full support. To get access to the full functionality, you either have to use a special function to get the address of the extended functions, or you use a library that has it all prepared. I would recommend GLEW for this. I have heard gl3w is also good, but haven't used it myself.

If you want to write code that is compatible with Linux and other platforms, I would recommend glfw for a minimal library that provides an interface to windows management and other input and output devices. Stay away from GLUT.


thank you very much Posted Image

I'm using Qt 4 (QtOpenGL4.dll) what do you think? That has nothing to do? I program for windows and mac osx Posted Image

My project (lol)

Edited by VitaliBR, 16 August 2012 - 11:37 AM.


#4 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 17 August 2012 - 02:32 AM

Thanks. I will have a look someday at QT with OpenGL for cross compilation on Ubuntu.

#5 larspensjo   Members   -  Reputation: 1557

Like
3Likes
Like

Posted 17 August 2012 - 02:52 AM

Qt is a big library, that gives you a lot of things. If you need these things, then it is fine. If not, using Qt is an overkill.

That is, if you are doing a dialog system outside of the OpenGL context, then Qt may be very good. But if you are doing the dialogs inside the OpenGL window, then you don't need Qt.

Judging by the demo above, it looks like Qt may be a good portable choice.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#6 VitaliBR   Members   -  Reputation: 147

Like
0Likes
Like

Posted 18 August 2012 - 04:26 AM

Qt is a big library, that gives you a lot of things. If you need these things, then it is fine. If not, using Qt is an overkill.

That is, if you are doing a dialog system outside of the OpenGL context, then Qt may be very good. But if you are doing the dialogs inside the OpenGL window, then you don't need Qt.

Judging by the demo above, it looks like Qt may be a good portable choice.


Yes, Qt is perfect for me :D

Using Qt, you mean that I no longer need to use the other as GLEW?

#7 larspensjo   Members   -  Reputation: 1557

Like
1Likes
Like

Posted 19 August 2012 - 12:59 AM

Using Qt, you mean that I no longer need to use the other as GLEW?

Qt gives you access to the OpenGL context, as well as many other user input/output resources. So with Qt you don't need GLUT or glfw.

GLEW makes it possible for you to get an access to the OpenGL specific API that is portable. I haven't used Qt myself, but a quick look shows there is the class QGLFunctions that seems to do the same thing. Someone else will have to comment on it. This link and link would seem to me that glew is preferable.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#8 VitaliBR   Members   -  Reputation: 147

Like
0Likes
Like

Posted 21 August 2012 - 04:09 AM


Using Qt, you mean that I no longer need to use the other as GLEW?

Qt gives you access to the OpenGL context, as well as many other user input/output resources. So with Qt you don't need GLUT or glfw.

GLEW makes it possible for you to get an access to the OpenGL specific API that is portable. I haven't used Qt myself, but a quick look shows there is the class QGLFunctions that seems to do the same thing. Someone else will have to comment on it. This link and linkwould seem to me that glew is preferable.


I would like someone to answer this question for both of us

and thanks for the explanation friend :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS