Archived

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

griffenjam

OpenGL
OpenGl and access violations...a sad story

6 posts in this topic

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 ------------------------------
0

Share this post


Link to post
Share on other sites
#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~
0

Share this post


Link to post
Share on other sites
I am reading from a file straight into bitmap.

read(bitmap, sizeof(unsigned char), datasize, fp);

Would a 2d array work with this?
0

Share this post


Link to post
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];
//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~
0

Share this post


Link to post
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
0

Share this post


Link to post
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?
I can worry about the bitmap loading being incorrect when I can actaully run my code,
as it is I can''t test anything.
0

Share this post


Link to post
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

try this in your code
bitmap = new unsigned char[imagesize*4];
instead of
bitmap = new unsigned char[imagesize];
0

Share this post


Link to post
Share on other sites

  • Similar Content

    • By Jon Alma
      Some time ago I implemented a particle system using billboarding techniques to ensure that the particles are always facing the viewer.  These billboards are always centered on one 3d coordinate.
      I would like to build on this and use billboarding as the basis for things like laser bolts and gunshots.  Here the difference is that instead of a single point particle I now have to draw a billboard between two points - the start and end of the laser bolt for example.  I appreciate that having two end points places limits on how much the billboard can be rotated to face the viewer, but I'm looking to code a best effort solution.  For the moment I am struggling to work out how to do this or find any tutorials / code examples that explain how to draw a billboard between two points ... can anyone help?
      Thanks.
    • By Sagaceil
      It's always better to fight with a bro.
    • By recp
      Hi,
      I'm working on new asset importer (https://github.com/recp/assetkit) based on COLLADA specs, the question is not about COLLADA directly
      also I'm working on a new renderer to render (https://github.com/recp/libgk) imported document.
      In the future I'll spend more time on this renderer of course, currently rendering imported (implemented parts) is enough for me
      assetkit imports COLLADA document (it will support glTF too),
      importing scene, geometries, effects/materials, 2d textures and rendering them seems working
      My actual confusion is about shaders. COLLADA has COMMON profile and GLSL... profiles,
      GLSL profile provides shaders for effects so I don't need to wory about them just compile, link, group them before render

      The problem occours in COMMON profile because I need to write shaders,
      Actually I wrote them for basic matrials and another version for 2d texture
      I would like to create multiple program but I am not sure how to split this this shader into smaller ones,

      Basic material version (only colors):
      https://github.com/recp/libgk/blob/master/src/default/shader/gk_default.frag
      Texture version:
      https://gist.github.com/recp/b0368c74c35d9d6912f524624bfbf5a3
      I used subroutines to bind materials, actually I liked it,
      In scene graph every node can have different program, and it switches between them if parentNode->program != node->program
      (I'll do scene graph optimizations e.g.  view frustum culling, grouping shaders... later)

      I'm going to implement transparency but I'm considering to create separate shaders,
      because default shader is going to be branching hell
      I can't generate shader for every node because I don't know how many node can be exist, there is no limit.
      I don't know how to write a good uber-shader for different cases:

      Here material struct:
      struct Material { ColorOrTexture emission; ColorOrTexture ambient; ColorOrTexture specular; ColorOrTexture reflective; ColorOrTexture transparent; ColorOrTexture diffuse; float shininess; float reflectivEyety; float transparency; float indexOfRefraction; }; ColorOrTexture could be color or 2d texture, if there would be single colorOrTex then I could split into two programs,
      Also I'm going to implement transparency, I am not sure how many program that I needed

      I'm considering to maintain a few default shaders for COMMON profile,
      1-no-texture, 2-one of colorOrTexture contains texture, 3-........

      Any advices in general or about how to optimize/split (if I need) these shaders which I provied as link?
      What do you think the shaders I wrote, I would like to write them without branching if posible,
      I hope I don't need to write 50+ or 100+ shaders, and 100+ default programs

      PS: These default shaders should render any document, they are not specific, they are general purpose...
             I'm compiling and linking default shaders when app launched

      Thanks
    • By CircleOfLight97
      Hi guys,
      I would like to contribute to a game project as a developer (open source possibly). I have some experiences in C/C++ in game development (perso projects). I don't know either unreal or unity but I have some knowledges in opengl, glsl and shading theory as I had some courses at university regarding to that. I have some knowledges in maths and basic in physics. I know a little how to use blender to do modelling, texturing and simple game assets (no characters, no animation no skinning/rigging). I have no game preferences but I like aventure game, dungeon crawler, platformers, randomly generated things. I know these kind of projects involve a lot of time and I'd be really to work on it but if there are no cleary defined specific design goals/stories/gameplay mechanics I would like to not be part of it x) and I would rather prefer a smaller but well defined project to work on that a huge and not 'finishable' one.
      CircleOfLight97
    • By gamesthatcouldbeworse
      Hi, I finally released KILL COMMANDO on gamejolt for free. It is a retro-funsplatter-shooter with C64 style. Give it a try.
  • Popular Now