• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# OpenGL OpenGl and access violations...a sad story

## Recommended Posts

I''m trying to use glDrawPixels() and am not having ANY luck. I''m sending an unsigned char * but when the function runs I get an ACCESS VIOLATION!!! When I debug it it looks like the violation is in one of my video cards driver files (nVidia GeForce 2). This is all happening inside a class, I was also getting access violations when trying to set a value in the array. That is fixed now (I don''t really know how). is this correct? unsigned char *bitmap; bitmap = new unsigned char[imagesize]; //load the bitmap . . glDrawPixels(,,,, bitmap); if so why am I getting access violations? also why would mearly setting a value in bitmap (bitmap[0] = ''a'' cause an acces violation? Jason Mickela ICQ : 873518 E-Mail: jmickela@pacbell.net ------------------------------ "Evil attacks from all sides but the greatest evil attacks from within." Me ------------------------------

##### Share on other sites
#define Height 64
#defein width 64
GLubyte *bitmap;

bitmap = new GLubyte bitmap[height][width];
.
.
glDrawPixels(Width, height, GL_RGB, GL_UNSIGNED_BYTE, bitmap);

make sure that the type ie ''GL_UNSIGNED_BYTE'' is the same type as the data u are using. the abouve code should work.. plz post a rply if it does/doesnt

~prevail by daring to fail~

##### Share on other sites
I am reading from a file straight into bitmap.

Would a 2d array work with this?

##### Share on other sites
shit i fogot to ass another array tot the bitmap array

#define Height 64
#defein width 64
GLubyte *bitmap;

bitmap = new GLubyte bitmap[height][width][3];
.
.
glDrawPixels(Width, height, GL_RGB, GL_UNSIGNED_BYTE, bitmap);

the following wont do ne thing. u dont know the actuall size of each variable ie a 24bpp bitmap will have 8bits (a byte) per color adn so the variables will have to be of type GLubyte || unsigned short (dont use char and all data will be unsigned!!!). and also if u load the entire file into the array u will also get the file header in with thae data and u dont want that. if u dont know the file structire of a bmp ull have to go find out so u can extract the depth information and the data offset from the begining of the file.

~prevail by daring to fail~

##### Share on other sites
>> bitmap = new unsigned char[imagesize]; <<

are u taking account of the images bitdepth eg
greyscale = imagesize*1
RGB = imagesize*3
RGBA = imagesize*4

##### Share on other sites
In my code I have already grabed the file header, that is where I got the imagesize value from.
No, I have not taken the type of image into account, none of the sample code that I have seen has either.
Nor would it matter for the question I am asking. IT doesn''t matter what I''m loading or it I''m loading it wrong, wrong data wouldn''t give an access violation, it jus''t wouldn''t work right.
AFAIK the statement
bitmap[1] = temp; //Where temp is of type unsigned char
should cause ANY problems.
I am testing to make sure I was able to allocate the memory.
Why am I getting access violations?
as it is I can''t test anything.

##### Share on other sites
u should get an access voilation (or some error)

ubyte data[2*2] // 4 pixels

glDrawPixels( GL_RGB, 2,2, ubyte, data ) // bang error

drawpixels wants 12 pixels ie 2x2x3 (3 cause its RGB) but youve only given it 4

bitmap = new unsigned char[imagesize*4];
bitmap = new unsigned char[imagesize];

• ### Forum Statistics

• Total Topics
627694
• Total Posts
2978673
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 19
• 14
• 12
• 10
• 12