OpenGl and access violations...a sad story
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
------------------------------
#define Height 64
#defein width 64
GLubyte *bitmap;
bitmap = new GLubyte bitmap[height][width];
//load the bitmap
.
.
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~
#defein width 64
GLubyte *bitmap;
bitmap = new GLubyte bitmap[height][width];
//load the bitmap
.
.
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~
I am reading from a file straight into bitmap.
read(bitmap, sizeof(unsigned char), datasize, fp);
Would a 2d array work with this?
read(bitmap, sizeof(unsigned char), datasize, fp);
Would a 2d array work with this?
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];
//load the bitmap
.
.
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.
read(bitmap, sizeof(unsigned char), datasize, fp);
~prevail by daring to fail~
#define Height 64
#defein width 64
GLubyte *bitmap;
bitmap = new GLubyte bitmap[height][width][3];
//load the bitmap
.
.
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.
read(bitmap, sizeof(unsigned char), datasize, fp);
~prevail by daring to fail~
>> bitmap = new unsigned char[imagesize]; <<
are u taking account of the images bitdepth eg
greyscale = imagesize*1
RGB = imagesize*3
RGBA = imagesize*4
are u taking account of the images bitdepth eg
greyscale = imagesize*1
RGB = imagesize*3
RGBA = imagesize*4
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?
I can worry about the bitmap loading being incorrect when I can actaully run my code,
as it is I can''t test anything.
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?
I can worry about the bitmap loading being incorrect when I can actaully run my code,
as it is I can''t test anything.
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
try this in your code
bitmap = new unsigned char[imagesize*4];
instead of
bitmap = new unsigned char[imagesize];
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
try this in your code
bitmap = new unsigned char[imagesize*4];
instead of
bitmap = new unsigned char[imagesize];
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement