PDA

View Full Version : Drawing primitives outside QGLWIdget



beginQT
22nd February 2012, 19:59
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!

beginQT
25th February 2012, 22:17
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.


void CPsxHMI_GLScreen_PDC::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

m_CarDim.g_Init_vd(objConfig_data->LCFG_Car_Width_sfl32*2.0946, objConfig_data->LCFG_Car_Length_sfl32*1.10);
m_CarPos.g_Init_vd(0.0f, 0.0f, 0.0f);
m_CarRot.g_Init_vd(0.0f,0.0f,0.0f,0.0f );

image.load(":/debug/PICS/Car_New.png");

m_ImgData.g_Img_Id_sint32 = bindTexture(image);
objGL_WindowSize->g_GLWindow_Setup_vd();
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

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.

//the line below is drawn too, no problems here. This is only test code though.
glBegin(GL_LINES);
glVertex3d( -2.0 , m_CarPos.g_YPOS_sfl32+3.0f , m_CarPos.g_ZPOS_sfl32 );
glVertex3d( 0.0f ,0.0f, 0.0f);
glEnd();
}



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



void CPsxHMI_PDCScreen_Settings::g_Draw_PDC_vd(g_GLPos_ st f_Pos, g_GLRot_st f_Rot )
{
//Positions of PDC data
g_GLPos_st l_PDC_POS_st;

sfloat32 l_Veh_Off_sfl32, l_X_Off_sfl32, l_Y_Off_sfl32;

//Front PDC Calculations

/* Offset position from Centre of the Vehicle */
l_Veh_Off_sfl32 = (objXML_Data->LCFG_Car_Length_sfl32/1.85 - objXML_Data->LCFG_Car_Width_sfl32/2);
l_X_Off_sfl32 = l_Veh_Off_sfl32 * qSin(-f_Rot.g_Angle_sfl32/DEG_TO_RAD);
l_Y_Off_sfl32 = l_Veh_Off_sfl32 * qCos(-f_Rot.g_Angle_sfl32/DEG_TO_RAD);

// Location of Front Lateral Zones
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 );

m_DrawPDC_FOV_vd
(
l_PDC_POS_st,
f_Rot,
LZ_Zone_5,
LZ_Pos_FRONT,
objXML_Data->LCFG_PDC_Green_Dist_Front_sfl32,
objXML_Data->LCFG_LateralZone_Angles_psint32
);
}


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.


void CPsxHMI_PDCScreen_Settings::m_DrawPDC_FOV_vd
(
g_GLPos_st f_Pos,
g_GLRot_st f_Rot,
g_LZ_Zone_en f_LZ_Zone,
g_LZ_Pos_en f_LZ_Pos,
sfloat32 f_Dist_psfl32,
sint32 *f_PDC_Ang_psint32
)
{
//Set the color of the FOV
g_GLColors_st l_PDC_Color_st;
l_PDC_Color_st.g_Init_vd(1.0f, 0.0f, 0.0f/*0.238f , 0.233f , 0.233f*/ );

//Surface data for MapGrid
g_SurfData_st l_Surface_st;
l_Surface_st.g_Init_vd(5 , 2 , 20 );
std::cout<<"m_DrawPDC_FOV_vd is called"<<std::endl;
//Array to receive data
sfloat32 *l_ZoneData_psfl32;

sfloat32 l_Min1_sfl32, l_Min2_sfl32;

for( sint32 l_sint32=0 ; l_sint32 < f_LZ_Zone ; l_sint32++ )
{
l_Min1_sfl32 = l_Min2_sfl32 = 0.20f;

switch(l_sint32)
{
case 2:
l_Min1_sfl32 -= 0.18f;
l_Min2_sfl32 -= 0.18f;
break;
case 3:
l_Min1_sfl32 -= 0.18f;
l_Min2_sfl32 -= 0.15f;
break;
case 1:
l_Min1_sfl32 -= 0.15f;
l_Min2_sfl32 -= 0.18f;
break;
case 4:
l_Min1_sfl32 -= 0.15f;
l_Min2_sfl32 -= 0.16f;
break;
default:
l_Min1_sfl32 -= 0.16f;
l_Min2_sfl32 -= 0.15f;
break;
}

//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.
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]);

if (f_LZ_Pos == LZ_Pos_REAR)
{
for (sint32 l_Rear_si32 = 0; l_Rear_si32 < sizeof(l_ZoneData_psfl32)/sizeof(l_ZoneData_psfl32[0]); l_Rear_si32++)
{
l_ZoneData_psfl32[l_Rear_si32] *= -1;
}
}

//the method where the draw routines are called.
m_DrawSurface_vd(f_Pos, f_Rot, l_PDC_Color_st, 1.0, l_Surface_st, l_ZoneData_psfl32);
delete [] l_ZoneData_psfl32;
}
}


Finally, the draw function now. all OpenGL commands for drawing are called from within here.


void CPsxHMI_PDCScreen_Settings::m_DrawSurface_vd
(
g_GLPos_st f_Pos,
g_GLRot_st f_Rot,
g_GLColors_st f_Color,
sint32 f_Transp,
g_SurfData_st f_Surface,
sfloat32 *f_ArrData)
{
/* Push indicates we dont disturb the current setup of drawing
and further changes adds to the present set */
glPushMatrix( );

/* Translate to the Position */
glTranslated( f_Pos.g_XPOS_sfl32 , f_Pos.g_YPOS_sfl32 , f_Pos.g_ZPOS_sfl32 );

/* Rotation of the position */
glRotatef( f_Rot.g_Angle_sfl32 , f_Rot.g_XROT_sfl32, f_Rot.g_YROT_sfl32 , f_Rot.g_ZROT_sfl32 );

/* Checking for Translucency */
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glEnable (GL_LINE_SMOOTH);
// Gl::glHint(Gl::GL_PERSPECTIVE_CORRECTION_HINT, Gl::GL_FASTEST);
/* Color of polygon inside */
glColor4f( f_Color.g_Red_sfl32 ,f_Color.g_Green_sfl32 , f_Color.g_Blue_sfl32 , f_Transp );

glBegin(GL_LINES);
glVertex3d( f_Pos.g_XPOS_sfl32 , f_Pos.g_YPOS_sfl32+1.0f , f_Pos.g_ZPOS_sfl32 );
glVertex3d( 0.0f ,0.0f, 0.0f);
glEnd();
/* Antialiasing the polygon edges before drawing */
glLineWidth(3.0f);
for( sint32 l=0; l < 4; l++)
{
glBegin(GL_LINES);
glVertex3d( f_ArrData[l *3 ] , f_ArrData[l *3 +1] , 0.0 );
glVertex3d( f_ArrData[l *3 +3] ,f_ArrData[l *3 +4] , 0.0 );
glEnd();
}

for(int i = 29; i >= 20;)
{
glBegin(GL_LINES);
glVertex3d( f_ArrData[i - 2] ,f_ArrData[i - 1] , 0.0 );
glVertex3d( f_ArrData[i - 5] ,f_ArrData[i - 4] , 0.0 );
glEnd();

i = i - 3;
}

/* draw the surface */
glLineWidth(1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_ALPHA_TEST);
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);
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(20, 0.0, 1.0, f_Surface.g_Polation_si32, 0.0, 1.0);

glEvalMesh2(GL_FILL, 0, f_Surface.g_Polation_si32, 0, f_Surface.g_Polation_si32 );


glDisable(GL_DEPTH_TEST );
glDisable(GL_ALPHA_TEST);
glDisable(GL_MAP2_VERTEX_3);
glDisable(GL_AUTO_NORMAL);

// Disable Alpha Channel
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);

/* Return the Screen back to normal scenario */
glPopMatrix();
}



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.

AlexSudnik
27th February 2012, 11:03
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 ).