Jump to content

  • Log In with Google      Sign In   
  • Create Account

The Magical Pot

Member Since 09 Aug 2011
Offline Last Active Jul 22 2014 08:17 AM

Topics I've Started

VBO and glIsBuffer

07 July 2014 - 06:59 AM

Hi!

 

I'm working with VBOs and I suddenly sumbled across a very weird error. My compiler is giving me a run-time error saying that this statement can't be executed:

if ( glIsBuffer( VertexBuffer ) )

This statement can be found in this destructor:

VBOQuad::~VBOQuad()
{
	//Clear vertex buffer
	if ( glIsBuffer( VertexBuffer ) )
		glDeleteBuffers( 1, &VertexBuffer );

	//Clear index buffer
	if ( glIsBuffer( IndexBuffer ) )
		glDeleteBuffers( 1, &IndexBuffer );

	VertexBuffer = NULL;
	IndexBuffer = NULL;
}

I've tried to track this error down to find some sort of context, but I've found that the run-time error emerges before the first line of the main function is executed. The description of glIsBuffer says that the function will return true if the argument is the name of an existing buffer, and it will return false if the argument is zero or a non-zero value. The debugger says:

 

VertexBuffer CXX0030: Error: expression cannot be evaluated
IndexBuffer CXX0030: Error: expression cannot be evaluated
 
 
This would, to me, indicate that VertexBuffer doesn't exist in memory, which in turn would mean that VertexBuffer is basically NULL, which is defined as zero, so there souldn't be a problem. That's probably not right since it's crashing at that statement.
 
The main problem I'm having is that the application crashes before the main function is executed, so for all I know, the destructor hasn't even been called yet, but it's trying to execute it, by the looks of it. My question is what the problem usually is in a situation like this where the application crashes before the main function is executed.
 
Thanks!
 
EDIT: I have added a screen dump of the Stack Trace.

Uptading parts of data in a VBO

16 February 2014 - 04:47 AM

Hi!

 

I'm currently trying to set up a function that renders a textured 2D quad using VBOs. The function changes the vertex data of the VBO every time it's called so that you can stretch it, but the texture data of the VBO doesn't change. In other words I want to be able to change the vertex data without having to change the texture data of the VBO.

 

When I store my VBO I have a struct that contains 4 GLfloats (VertexData2D), the first two GLfloats represent the vertex data and the last two GLfloats represent the texture data. My problem is that I can't find a way to only change the vertex data without having to change the texture data, since the entire VBO contains both vertex data and texture data.

 

This the rendering part in the function:

glBindTexture( GL_TEXTURE_2D, get_texture_id() );		//Set texture

    //Enable vertex and texture coordinate arrays
    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableClientState( GL_TEXTURE_COORD_ARRAY );

glBindBuffer( GL_ARRAY_BUFFER, VertexDataBuffer );		//Bind vertex data

//Update vertex buffer data
glBufferSubData( GL_ARRAY_BUFFER, 0, 4 * 4 * sizeof(GLfloat), VData );	

//Set texture coordinate data
glTexCoordPointer( 2, GL_FLOAT, 4 * sizeof(GLfloat), (GLvoid*)offsetof( VertexData2D, TexCoord ) );		
//Set vertex data
glVertexPointer( 2, GL_FLOAT, 4 * sizeof(GLfloat), (GLvoid*)offsetof( VertexData2D, Position ) );		

//Draw quad using vertex data and index data
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, IndexBuffer );
glDrawElements( GL_QUADS, 4, GL_UNSIGNED_INT, NULL );

    //Disable vertex and texture coordinate arrays
    glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    glDisableClientState( GL_VERTEX_ARRAY );

I first bind the correct texture and VBO, then update the VBO using

glBufferSubData() 

 (the VBO is set with GL_DYNAMIC_DRAW). I update the VBO starting at index 0, VData is the VBO that's going to replace the current one. Each vertex has the size 

4 * sizeof(GLfloat)

and since I'm rendering a quad, the stride results in

4 * 4 * sizeof(GLfloat)

It's in glBufferSubData() that the problem is, my VBO contains both the vertex data and texture data, but I only want to change the vertex data. glBufferSubData() overwrites the current VBO, but I only want it to overwrite parts of it. This is essentially how I want it to work:

 

Update memory equal to: 2 * sizeof(GLfloat)

Skip memory equal to: 2 * sizeof(GLfloat)

Repeat 3 more times

 

What should I do? Is there another function that can do this?

 

Thank you!


Using cosine, sine, tangent etc. in C++

14 August 2013 - 07:08 AM

Hi!

 

I don't need to go into detail of what I'm doing to get an answer on this question. All I'm wondering is what function in the cmath.h header that corresponds to cos-1, sin-1, tan-1 on a calculator.

For example: if I want to calculate cos-1(200/100) to get the degree of an angle, which function do I use since functions cos(), sin(), tan() in C++ corresponds to cos, sin, tan on a calculator and not cos-1, sin-1, tan-1.

 

Hopefully, that was not a load of incohesive dribble, but let me know if you want me to explain some more if it was :)


Utilizing the alpha channel on an image with OpenGL

17 July 2013 - 12:17 PM

Hi!

 

I'm making a game using SDL and OpenGL and I've thought about how I should handle transparency in images. I don't think color keying is a good option, so the method I'm going to use is that I'm going to utilize the alpha channel on images. If I've understood it right, you have to tell the computer what the alpha channel means, so what I would want to do is to tell the computer that the alpha channel represents transparency. When I try to use the alpha channel for transparency, every pixel that doesn't have 100% opacity is given the color FFFFFF.

 

My question is simply: how do I set the alpha channel to transparency with OpenGL?


Problems with storing fractions in variables

10 May 2013 - 12:13 PM

Hello!

 

I'm using OpenGL to render things in my game, but I'm haveing some problems. OpenGL uses decimals/fractions between 0 and 1 to locate pixels in a given texture. (for example, if I want to locate the 8th pixel on the x-axis in an image that's 32 pixels wide, I would type 'x=8/32' instead of 'x=8')

The problem is that I can't put fractions into float variables, (which would be convenient in my code) I can only use decimals. I can't write 'float x = 8/32' because the result of 8/32 isn't 0.25, but when I write 'float x = 0.25' it works perfectly.

 

This is a snippet that demonstrates how I render:

 

 

glBegin( GL_QUADS );
       glTexCoord2f( 0.f, 0.f );    glVertex2f(    0.f,   0.f );
       glTexCoord2f( 8/32, 0.f );    glVertex2f( 8.f,   0.f );
       glTexCoord2f( 8/32, 8/32 ); glVertex2f( 8.f, 8.f );
       glTexCoord2f( 0.f, 8/32 ); glVertex2f( 0.f, 8.f );
glEnd();

 

I just wanted to ask this question before I start a suboptimal solution. Am I missing something or do I have to work around it? Am I using the wrong type of variables to store fractions? Is it the 'glTexCoord2f' function that's the problem?

 

Thanks.


PARTNERS