PDA

View Full Version : VBO Problems



dagute
10-25-2012, 03:53 AM
Hello from germany

I have stored some objects as VBOs an everything works fine.
If i draw an additional text - created with wglUseOutlineFonts and stored as display lists
the VBO color - which is not transparent alpah=255 becomes transparent and the
normals look scrambled??
Hoe is it possible to modify the content of a VBO without accessing its memory??

kind regards
Peter

thokra
10-25-2012, 04:03 AM
Code please.

dagute
10-25-2012, 04:33 AM
Hello

any combination of VBOs with any color combinations etc. works fine.
As soon as I display text the VBO colors are transparent.

extern void Str_3D( Vertex_Struct* pos, char *str, int32_t fnt_ind, RGBA_Struct* col, BOOL cen_flag )
{
float lg = 0;
uint32_t c1;

if ( str == NULL ) return;

glPushMatrix();
if( cen_flag )
{
for( c1 = 0; c1 < strlen( str ); c1++ ) lg +=__gmf[ fnt_ind ][ str[ c1 ] ].gmfCellIncX;
glTranslatef( -lg / 2.0f + pos->x, pos->y - 0.35f, pos->z + 0.005f );
}
else
{
glTranslatef( pos->x, pos->y - 0.35f, pos->z + 0.005f );
}

glPushAttrib( GL_LIST_BIT );
glColor4ubv( &col->red );
glListBase( __f_base[ fnt_ind ] );
glCallLists( strlen( str ), GL_UNSIGNED_BYTE, str );
glPopAttrib();
glPopMatrix();
}


static void Draw_GL_Scene( void )
{
int32_t c1;
int32_t c2;
VBO_Data_Struct* vbd;

glPushMatrix();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glRotatef( _c_ang, 1.0, 0.0, 0.0 );
glCallList( _ax_3d );

Str_3D( &vx_0, "CE_WIN", 0, &_col[ 1 ], TRUE );
Draw_VBO( _vbo[ 0 ] );
Draw_VBO( _vbo[ 1 ] );

glPopMatrix();

glFlush();

_c_ang += 0.03f;


}

kind regards
Peter

thokra
10-25-2012, 05:12 AM
Ah display lists, aren't they just fun?

Have you tried


glPushAttrib(GL_ALL_ATTRIB_BITS);

instead of


glPushAttrib(GL_LIST_BIT);

? If this changes everything back to normal, you can assume it's stuff in the WGL generated DLs that messes up your state.

What state is set for the list called with
glCallList( _ax_3d ); ?

EDIT: Please format you post to use '['code']' ... '['/code']' tags. It's hard enough to read as it is.

dagute
10-25-2012, 05:56 AM
Hi thanks for your reply

if I change to GL_ALL_ATTRIB_BITS the text does not display any more
I have taken out glCallList( _ax_3D )

the first frame is rendered correct - the second is bad

I've just seen you are from germany - me too -> so we can go on german???

Is there any possibility to place the chars in VBOs - I need to rotate scale.. them

thokra
10-25-2012, 06:04 AM
so we can go on german???

Nope, the language is this forum is English. Period.

Can you revert the attrib push and post screen shots of correct vs. incorrect? I fail to see what's going wrong with your colors at the moment.

dagute
10-25-2012, 06:23 AM
Thank god this is not a japanese forum

Assume a solid cube color = 255, 255, 255, 255 -> white no transparency,
in the center of the cube is my text.
The first frame shows only the cube -> correct
the second frame shows the cube transparent with the text visible at its center

When I change to GL_ALL_ATTRIB_BITS there is no text anywhere.

thokra
10-25-2012, 06:42 AM
Thank god this is not a japanese forum

Stop being racist. ;)


the second frame shows the cube transparent

I just read the MSDN docs about wglUseFontOutline and before coming to a conclusion I'd like to know, do you mean invisible when saying transparent?

dagute
10-25-2012, 06:49 AM
Hi

no the cube is visible - but as its color is like 255, 255, 255, 128 -> with a scaled alpha value

thokra
10-25-2012, 06:53 AM
_col is defined how?

dagute
10-25-2012, 07:34 AM
glColorMaterial

thokra
10-25-2012, 07:49 AM
Yeah, I meant more like the actual values...

EDIT: BTW, why do you have blending enabled anyway? I can't see wglUseFontOutlines doing that.

dagute
10-25-2012, 07:50 AM
glColorMaterial

thokra
10-25-2012, 08:07 AM
Dude, glColorMaterial is a state setting command taking only GL defined compile time constants. It says nothing about actual color values specified for the allowed parameters.

The reason I want to know is because you call glColor4ubv before calling the font lists.

dagute
10-25-2012, 08:38 AM
I cannot follow you, I hand a rgba value to the function that holds the base color of the text.
whats wrong with it??
I thought a vbo whose vertics color alpha value is 255 can never be transparent, no matter who the lightning or material setup is....wrong???

thokra
10-25-2012, 08:51 AM
How can I know if you have defined a vertex color array that sets the vertices color values when rendering? I know nothing about your VBO setup, I know nothing about state settings you have done at init time or somewhere else, I know nothing about how you render vertex data and I know nothing about what what color values you pass to glColor4ubv.

So, tell me, how am I supposed to help you if you won't even supply me with information I'm specifically asking for?

All I can deduce is that you probably have blending enabled, maybe have not specified a vertex color array and that you don't reset the the state of GL_CURRENT_COLOR to whatever value it's supposed to have after glColor4ubv...

dagute
10-25-2012, 09:03 AM
My vbos keep koordinates, normals and colors for each Vertex - no textures.
There is no need to specify any color, if I want a different I modify the color fileds of the vbo vertices.
The display lists as delivered from wgl... hold only polygon vertics - so the color must be defined external.
Sorry if my description was incomplete.
Hope this helps - somehow the execution of the lists changes the opengl state - as I told you before the first frame is ok,
on the second frame the vbo color is transparent.
If I only work with vbos everything works perfect.
Maybe I should define the characters as vbos.

thokra
10-25-2012, 09:09 AM
somehow the execution of the lists changes the opengl state

Yes, that's definitely possible. However, they would have to enable GL_BLEND for blending to happen - unless you don't enable it somewhere else yourself. And even if it was enabled, if you have a valid color array used when rendering with correctly setup VBO, color state should be pulled from the VBOs. Please post your VBO and array (gl*Pointer() ) setup code and Draw_VBO().

dagute
10-25-2012, 09:35 AM
I use 3 function for every primitive - example here ( I cut out the other planes ) VBO_Quad -> creates the data in the machines memory
Upload_VBO transfers everything to GPU memory
Draw_VBO displays it



extern VBO_Struct* VBO_Quad( GLfloat lg_x, GLfloat lg_y, GLfloat lg_z, RGBA_Struct* base_col )
{
VBO_Struct* vbo;
VBO_Index_Buffer_Struct* ib;
VBO_Data_Struct* vdr;
int c1;

lg_x /= 2.0f; lg_y /= 2.0f; lg_z /= 2.0f;

vbo = Create_VBO_Struct(); // Erzeuge das VOB_1_Struct
Init_VBO_Struct( vbo, 24, 1 ); // Initialisiere es mit 8 vboertices und 1 Indexbuffer
vbo->idb_ptr[ 0 ] = Init_VBO_Index_Buffer_Struct( 24 ); // ein Indexbuffer mit 24 Einträgen

vdr = vbo->vb;

/*************************************/
/* Vertics Vorderseite <> 0 -- 3 */
/*************************************/
vdr->vx.x = -lg_x; vdr->vx.y = -lg_y; vdr->vx.z = lg_z; memcpy( &vdr->v_norm, &_z_plus_norm, vertex_struct_size ); memcpy( &vdr->col, base_col, rgba_struct_size ); vdr++;
vdr->vx.x = lg_x; vdr->vx.y = -lg_y; vdr->vx.z = lg_z; memcpy( &vdr->v_norm, &_z_plus_norm, vertex_struct_size ); memcpy( &vdr->col, base_col, rgba_struct_size ); vdr++;
vdr->vx.x = lg_x; vdr->vx.y = lg_y; vdr->vx.z = lg_z; memcpy( &vdr->v_norm, &_z_plus_norm, vertex_struct_size ); memcpy( &vdr->col, base_col, rgba_struct_size ); vdr++;
vdr->vx.x = -lg_x; vdr->vx.y = lg_y; vdr->vx.z = lg_z; memcpy( &vdr->v_norm, &_z_plus_norm, vertex_struct_size ); memcpy( &vdr->col, base_col, rgba_struct_size ); vdr++;


ib = vbo->idb_ptr[ 0 ];
ib->draw_id = 8; // Quads
for( c1 = 0; c1 < 24; c1++ ) ib->i_ptr[ c1 ] = c1;

return( vbo );

}

extern int32_t VBO_Upload( VBO_Struct* vbo )
{
VBO_Index_Buffer_Struct* v_idb;
uint32_t c1;

glGenBuffers( 1, &vbo->id );
glBindBuffer( GL_ARRAY_BUFFER, vbo->id );
glBufferData( GL_ARRAY_BUFFER, vbo->vb_size, vbo->vb, GL_DYNAMIC_DRAW );

for( c1 = 0; c1 < vbo->idb_numb; c1++ )
{
v_idb = vbo->idb_ptr[ c1 ];
glGenBuffers( 1, &v_idb->id );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, v_idb->id );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, v_idb->size, v_idb->i_ptr, GL_STATIC_DRAW );
}
return( 1 );
}


extern void Draw_VBO( VBO_Struct* vbo )
{
VBO_Index_Buffer_Struct* v_ib;
uint32_t c1;

glBindBuffer( GL_ARRAY_BUFFER, vbo->id );
glColorPointer ( 4, GL_UNSIGNED_BYTE, vbo->stride, vbo->col_offset ); // Colorpointer setzen
glVertexPointer( 3, GL_FLOAT, vbo->stride, vbo->vertex_offset ); // Vertexpointer setzen
glNormalPointer( GL_FLOAT, vbo->stride, vbo->normal_offset ); // Normalenpointer setzen

for( c1 = 0; c1 < vbo->idb_numb; c1++ )
{
v_ib = vbo->idb_ptr[ c1 ]; // Pointer auf Indexbuffer
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, v_ib->id ); // Indexbuffer aktivieren
switch( v_ib->draw_id )
{

case 2: // GL_LINE_STRIP
{
glDrawElements( GL_LINE_STRIP, v_ib->numb, GL_UNSIGNED_INT, NULL ); // TRIANGLES zeichnen
break;
}

case 4: // GL_TRIANGLES
{
glDrawElements( GL_TRIANGLES, v_ib->numb, GL_UNSIGNED_INT, NULL ); // TRIANGLES zeichnen
break;
}

case 5: // TRIANGLE_FAN
{
glDrawElements( GL_TRIANGLE_FAN, v_ib->numb, GL_UNSIGNED_INT, NULL ); // TRIANGLE_FAN zeichnen
break;
}

case 7: // POLYGON
{
glDrawElements( GL_POLYGON, v_ib->numb, GL_UNSIGNED_INT, NULL ); // POLYGON zeichnen
break;
}

case 8: // GL_QUADS
{
glDrawElements( GL_QUADS, v_ib->numb, GL_UNSIGNED_INT, NULL ); // QUADS zeichnen
break;
}

case 9: // GL_STRIP
{
glDrawElements( GL_QUAD_STRIP, v_ib->numb, GL_UNSIGNED_INT, NULL ); // QUADS_STRIP zeichnen
break;
}


} // Ende des switch Blocks


}

glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );

}

thokra
10-26-2012, 02:40 AM
Maybe it's just me, but other than finding your code extremely hard to read, I'm not yet able to see how your complete data is put into the VBO data store. Aside from that, if your data is all in one buffer, I doubt that a single vbo->stride argument will suffice because it looks to me as if you try to interleave your data and thus a single stride parameter cannot be appropriate. Please post the definitions of:


VBO_Struct* vbo;
VBO_Index_Buffer_Struct* ibM
VBO_Data_Struct* vdr;

dagute
10-26-2012, 12:02 PM
Here are the structure definitions
basically it is one Array with vertex definitions -> koordiantes, normales, colors
and any number of Indexarrays to work with this vertics



typedef struct
{
RGBA_Struct col;
Vertex_Struct vx;
Vertex_Struct v_norm;
} VBO_Data_Struct;



typedef struct
{
GLuint id;
int32_t draw_id;
GLuint* i_ptr;
GLuint numb;
GLuint size;
} VBO_Index_Buffer_Struct;



typedef struct
{
GLuint id;
VBO_Data_Struct* vb;
GLuint vb_numb;
GLuint vb_size;
GLuint idb_numb;
VBO_Index_Buffer_Struct** idb_ptr;
GLuint stride;
GLvoid* col_offset;
GLvoid* vertex_offset;
GLvoid* normal_offset;
} VBO_Struct;