Results 1 to 3 of 3

Thread: Drawing primitives outside QGLWIdget

  1. #1
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Drawing primitives outside QGLWIdget

    Hello,

    I am using an instance of QGLWIdget to handle my UI requirements. However, I also need to make calls to specific GL Commands for rendering into UI. The function which has this GL commands is in a seperate helper class(not a QGLWidget) but its been called from PaintGL of my QGLWidget instance. when I execute some GL commands from PaintGL method I could see its rendering. I am not very sure how to share the context between my QGLWidget and the Helper class.

    Could you please help me understand how the contexts been shared between QGLWidget and my Helper class, so that I can use the helper classes for different features instead of doing everything inside QGLWIdget.

    Thanks in Advance!

  2. #2
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Drawing primitives outside QGLWIdget

    Hello again,
    I've not yet been able to figure out the problem I've mentioned in my original post. I've put in some of the code that I've written in trying to achieve drawing on the screen using a helper class from my QGLWidget instance. This class, though, does not extend from any QT class.

    Firstly, I've the paintGL method in my QGLWidget instance.
    Qt Code:
    1. void CPsxHMI_GLScreen_PDC::paintGL()
    2. {
    3. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    4.  
    5. m_CarDim.g_Init_vd(objConfig_data->LCFG_Car_Width_sfl32*2.0946, objConfig_data->LCFG_Car_Length_sfl32*1.10);
    6. m_CarPos.g_Init_vd(0.0f, 0.0f, 0.0f);
    7. m_CarRot.g_Init_vd(0.0f,0.0f,0.0f,0.0f );
    8.  
    9. image.load(":/debug/PICS/Car_New.png");
    10.  
    11. m_ImgData.g_Img_Id_sint32 = bindTexture(image);
    12. objGL_WindowSize->g_GLWindow_Setup_vd();
    13. objGL_ImageLoad->g_LoadPicData_vd(m_CarPos, m_CarRot, m_CarDim, m_ImgData.g_Img_Id_sint32); //this works, the loaded image is seen on the screen
    14.  
    15. objPDC_Screen->g_Draw_PDC_vd(m_CarPos, m_CarRot); //this doesn't draw anything on screen; that's the problem I'm facing. code added below.
    16.  
    17. //the line below is drawn too, no problems here. This is only test code though.
    18. glBegin(GL_LINES);
    19. glVertex3d( -2.0 , m_CarPos.g_YPOS_sfl32+3.0f , m_CarPos.g_ZPOS_sfl32 );
    20. glVertex3d( 0.0f ,0.0f, 0.0f);
    21. glEnd();
    22. }
    To copy to clipboard, switch view to plain text mode 


    Below is the code from g_Draw_PDC_vd() method as called by the objPDC_Screen object (called in the paintGL method as above).

    Qt Code:
    1. void CPsxHMI_PDCScreen_Settings::g_Draw_PDC_vd(g_GLPos_st f_Pos, g_GLRot_st f_Rot )
    2. {
    3. //Positions of PDC data
    4. g_GLPos_st l_PDC_POS_st;
    5.  
    6. sfloat32 l_Veh_Off_sfl32, l_X_Off_sfl32, l_Y_Off_sfl32;
    7.  
    8. //Front PDC Calculations
    9.  
    10. /* Offset position from Centre of the Vehicle */
    11. l_Veh_Off_sfl32 = (objXML_Data->LCFG_Car_Length_sfl32/1.85 - objXML_Data->LCFG_Car_Width_sfl32/2);
    12. l_X_Off_sfl32 = l_Veh_Off_sfl32 * qSin(-f_Rot.g_Angle_sfl32/DEG_TO_RAD);
    13. l_Y_Off_sfl32 = l_Veh_Off_sfl32 * qCos(-f_Rot.g_Angle_sfl32/DEG_TO_RAD);
    14.  
    15. // Location of Front Lateral Zones
    16. l_PDC_POS_st.g_Init_vd( f_Pos.g_XPOS_sfl32 + l_X_Off_sfl32 , f_Pos.g_YPOS_sfl32 + l_Y_Off_sfl32 , 5.0f );
    17.  
    18. m_DrawPDC_FOV_vd
    19. (
    20. l_PDC_POS_st,
    21. f_Rot,
    22. LZ_Zone_5,
    23. LZ_Pos_FRONT,
    24. objXML_Data->LCFG_PDC_Green_Dist_Front_sfl32,
    25. objXML_Data->LCFG_LateralZone_Angles_psint32
    26. );
    27. }
    To copy to clipboard, switch view to plain text mode 

    This method performs calculations and sets the data for the required drawing and makes a call to another method that calls OpenGL commands for drawing.
    Qt Code:
    1. void CPsxHMI_PDCScreen_Settings::m_DrawPDC_FOV_vd
    2. (
    3. g_GLPos_st f_Pos,
    4. g_GLRot_st f_Rot,
    5. g_LZ_Zone_en f_LZ_Zone,
    6. g_LZ_Pos_en f_LZ_Pos,
    7. sfloat32 f_Dist_psfl32,
    8. sint32 *f_PDC_Ang_psint32
    9. )
    10. {
    11. //Set the color of the FOV
    12. g_GLColors_st l_PDC_Color_st;
    13. l_PDC_Color_st.g_Init_vd(1.0f, 0.0f, 0.0f/*0.238f , 0.233f , 0.233f*/ );
    14.  
    15. //Surface data for MapGrid
    16. g_SurfData_st l_Surface_st;
    17. l_Surface_st.g_Init_vd(5 , 2 , 20 );
    18. std::cout<<"m_DrawPDC_FOV_vd is called"<<std::endl;
    19. //Array to receive data
    20. sfloat32 *l_ZoneData_psfl32;
    21.  
    22. sfloat32 l_Min1_sfl32, l_Min2_sfl32;
    23.  
    24. for( sint32 l_sint32=0 ; l_sint32 < f_LZ_Zone ; l_sint32++ )
    25. {
    26. l_Min1_sfl32 = l_Min2_sfl32 = 0.20f;
    27.  
    28. switch(l_sint32)
    29. {
    30. case 2:
    31. l_Min1_sfl32 -= 0.18f;
    32. l_Min2_sfl32 -= 0.18f;
    33. break;
    34. case 3:
    35. l_Min1_sfl32 -= 0.18f;
    36. l_Min2_sfl32 -= 0.15f;
    37. break;
    38. case 1:
    39. l_Min1_sfl32 -= 0.15f;
    40. l_Min2_sfl32 -= 0.18f;
    41. break;
    42. case 4:
    43. l_Min1_sfl32 -= 0.15f;
    44. l_Min2_sfl32 -= 0.16f;
    45. break;
    46. default:
    47. l_Min1_sfl32 -= 0.16f;
    48. l_Min2_sfl32 -= 0.15f;
    49. break;
    50. }
    51.  
    52. //this array is finally sent to the draw function. the array is populated in the m_GetPDC_DATA_psfl32() method. the data is returned as expected.
    53. l_ZoneData_psfl32 = m_GetPDC_DATA_psfl32(l_Min1_sfl32, l_Min2_sfl32, f_Dist_psfl32, f_PDC_Ang_psint32[l_sint32], f_PDC_Ang_psint32[l_sint32 + 1]);
    54.  
    55. if (f_LZ_Pos == LZ_Pos_REAR)
    56. {
    57. for (sint32 l_Rear_si32 = 0; l_Rear_si32 < sizeof(l_ZoneData_psfl32)/sizeof(l_ZoneData_psfl32[0]); l_Rear_si32++)
    58. {
    59. l_ZoneData_psfl32[l_Rear_si32] *= -1;
    60. }
    61. }
    62.  
    63. //the method where the draw routines are called.
    64. m_DrawSurface_vd(f_Pos, f_Rot, l_PDC_Color_st, 1.0, l_Surface_st, l_ZoneData_psfl32);
    65. delete [] l_ZoneData_psfl32;
    66. }
    67. }
    To copy to clipboard, switch view to plain text mode 

    Finally, the draw function now. all OpenGL commands for drawing are called from within here.
    Qt Code:
    1. void CPsxHMI_PDCScreen_Settings::m_DrawSurface_vd
    2. (
    3. g_GLPos_st f_Pos,
    4. g_GLRot_st f_Rot,
    5. g_GLColors_st f_Color,
    6. sint32 f_Transp,
    7. g_SurfData_st f_Surface,
    8. sfloat32 *f_ArrData)
    9. {
    10. /* Push indicates we dont disturb the current setup of drawing
    11. and further changes adds to the present set */
    12. glPushMatrix( );
    13.  
    14. /* Translate to the Position */
    15. glTranslated( f_Pos.g_XPOS_sfl32 , f_Pos.g_YPOS_sfl32 , f_Pos.g_ZPOS_sfl32 );
    16.  
    17. /* Rotation of the position */
    18. glRotatef( f_Rot.g_Angle_sfl32 , f_Rot.g_XROT_sfl32, f_Rot.g_YROT_sfl32 , f_Rot.g_ZROT_sfl32 );
    19.  
    20. /* Checking for Translucency */
    21. glEnable(GL_BLEND);
    22. glDisable(GL_TEXTURE_2D);
    23. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    24.  
    25. glEnable (GL_LINE_SMOOTH);
    26. // Gl::glHint(Gl::GL_PERSPECTIVE_CORRECTION_HINT, Gl::GL_FASTEST);
    27. /* Color of polygon inside */
    28. glColor4f( f_Color.g_Red_sfl32 ,f_Color.g_Green_sfl32 , f_Color.g_Blue_sfl32 , f_Transp );
    29.  
    30. glBegin(GL_LINES);
    31. glVertex3d( f_Pos.g_XPOS_sfl32 , f_Pos.g_YPOS_sfl32+1.0f , f_Pos.g_ZPOS_sfl32 );
    32. glVertex3d( 0.0f ,0.0f, 0.0f);
    33. glEnd();
    34. /* Antialiasing the polygon edges before drawing */
    35. glLineWidth(3.0f);
    36. for( sint32 l=0; l < 4; l++)
    37. {
    38. glBegin(GL_LINES);
    39. glVertex3d( f_ArrData[l *3 ] , f_ArrData[l *3 +1] , 0.0 );
    40. glVertex3d( f_ArrData[l *3 +3] ,f_ArrData[l *3 +4] , 0.0 );
    41. glEnd();
    42. }
    43.  
    44. for(int i = 29; i >= 20;)
    45. {
    46. glBegin(GL_LINES);
    47. glVertex3d( f_ArrData[i - 2] ,f_ArrData[i - 1] , 0.0 );
    48. glVertex3d( f_ArrData[i - 5] ,f_ArrData[i - 4] , 0.0 );
    49. glEnd();
    50.  
    51. i = i - 3;
    52. }
    53.  
    54. /* draw the surface */
    55. glLineWidth(1.0f);
    56. glEnable(GL_DEPTH_TEST);
    57. glEnable(GL_ALPHA_TEST);
    58. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, f_Surface.g_X_si32 , 0, 1, f_Surface.g_X_si32*3 , f_Surface.g_Y_si32 , f_ArrData);
    59. glEnable(GL_MAP2_VERTEX_3);
    60. glEnable(GL_AUTO_NORMAL);
    61. glMapGrid2f(20, 0.0, 1.0, f_Surface.g_Polation_si32, 0.0, 1.0);
    62.  
    63. glEvalMesh2(GL_FILL, 0, f_Surface.g_Polation_si32, 0, f_Surface.g_Polation_si32 );
    64.  
    65.  
    66. glDisable(GL_DEPTH_TEST );
    67. glDisable(GL_ALPHA_TEST);
    68. glDisable(GL_MAP2_VERTEX_3);
    69. glDisable(GL_AUTO_NORMAL);
    70.  
    71. // Disable Alpha Channel
    72. glDisable(GL_BLEND);
    73. glDisable(GL_LINE_SMOOTH);
    74.  
    75. /* Return the Screen back to normal scenario */
    76. glPopMatrix();
    77. }
    To copy to clipboard, switch view to plain text mode 

    I've been trying a lot to get this working, but something is amiss and I haven't found it yet. Any hints/suggestions/findings would be very helpful.
    Thanks again.

  3. #3
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drawing primitives outside QGLWIdget

    Hm, i can't see a single line in your last method where you actually say what rendering context is used for rendering (which seem to be CPsxHMI_GLScreen_PDC ).

Similar Threads

  1. OpenGL drawing outside QGLWidget
    By zzz9 in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2012, 15:34
  2. Replies: 7
    Last Post: 1st July 2011, 01:21
  3. Replies: 0
    Last Post: 28th April 2011, 18:40
  4. QGLWidget tearing when drawing video
    By koan in forum Qt Programming
    Replies: 0
    Last Post: 9th October 2010, 16:24
  5. qglwidget not always drawing
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2009, 19:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.