Jump to content
  • Advertisement

Archived

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

Boops

OpenGL OpenGL with SDL

This topic is 5280 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m using OpenGL with SDL, so I set up an opengl screen and can draw triangles and quads on it and stuff. Now I want, after those things are drawn, to be able to draw a few individual pixels over that what opengl has drawn. I set up the screen as follows: SDL_Surface *scr; scr=SDL_SetVideoMode(width,height,bpp,flags); where flags contains SDL_OpenGL. Then I draw opengl stuff on it, and then I try to access the scr surface directly with:
void pset(int x, int y, Uint8 R, Uint8 G, Uint8 B)
{
  Uint32 color = SDL_MapRGB(scr->format, R, G, B);

        Uint32 *bufp;
        bufp = (Uint32 *)scr->pixels + (y%h)*scr->pitch/4 + x%w;
        *bufp = color;
}
 
And it crashes! Any idea why this could be, or if it''s even possible to do SDL graphic stuff if you have opengl running on that surface? Another question, I want to use my own bmp loader for the textures, so I have to somehow access all pixels of the opengl texture type to insert my bmp from a buffer into it. How can I do this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Boops
Any idea why this could be, or if it''s even possible to do SDL graphic stuff if you have opengl running on that surface?

No, as of now, it''s not possible.
quote:
Original post by Boops
Another question, I want to use my own bmp loader for the textures, so I have to somehow access all pixels of the opengl texture type to insert my bmp from a buffer into it. How can I do this?

When you call glTexImage2D you pass the data you want to use for the image. You can later change parts of the data (but not the image dimensions or format) with glTexSubImage2D.

Share this post


Link to post
Share on other sites
Thanks for the help. I tried glTexture2D(), but for some reason it doens't work. But wit gluBuild2DMipmaps() it works!

this doesn't work:

glTexImage2D( GL_TEXTURE_2D,3,3,48,48,1,GL_RGB,GL_UNSIGNED_BYTE,data);


and this works:


gluBuild2DMipmaps( GL_TEXTURE_2D, 3, 48, 48, GL_RGB, GL_UNSIGNED_BYTE, data );


Because I'm actually using opengl for a 2D tile game, I wouldn't like mipmapping to be used and be sure that it always uses the base texture, so I'd like to use GL_TEXTURE_2D, but all I get is a white surface, while gluBuild2DMipmaps with exactly the same data gives the texture. How to do what I want? (making sure it doesn't use lower resolution mipmaps for my tile game)? EDIT: also how to turn of the blurring (smoothing?)?

Also, I use 48*48 textures, and it seems to work on my computer, will it work everywhere or is it safer to use powers of two?

And, does there exist a handy way to calculate where GL_QUADS you draw will appear on screen, so, that the quads take up 48*48 screen pixels (same size as their texture), like one would want for a tile game?

Sorry, but another question: is there some specific camera matrix that I should use for a 2D tile game in opengl? I guess I don't want perspective mapping but that other sort of projection I can't think of it's name now but it's perpendicular and objects have the same size at all distances

[edited by - Boops on March 5, 2004 9:15:26 PM]

Share this post


Link to post
Share on other sites
Unless your OpenGL implementation supports GL_ARB_texture_non_power_of_two the image passed to glTexImage2D must have a power of two width and height (although they can be different values). gluBuild2DMipmaps automatically scales the image (rounding up, I presume) for the base level (and, obviously, for each of the sub-levels for the mipmap). For a simple solution, I suggest scaling (up) the image yourself before passing it to glTexImage2D if you don''t need mipmaps (otherwise, relying on GLU to do it for you might be good enough). The distortion is often not noticable. If it absolutely necessary to keep it the same size and you can sacrifice texture coordinate repeating (a.k.a., wrapping or tiling), you can just stuff the image in the lower left (or any other) corner of a texture and use texture coordinates to only select that portion of the texture.

Share this post


Link to post
Share on other sites
quote:
Original post by Null and Void
gluBuild2DMipmaps automatically scales the image (rounding up, I presume) for the base level (and, obviously, for each of the sub-levels for the mipmap).


Thanks! I''ll do it the way you said (using the lower left corner), I just want to keep 48x48 tiles since 32x32 looks too small and 64x64 looks too big
gluBuild2DMipmaps did a VERY ugly job at scaling the image, I''m glad I now got rid of it

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The NeHe basecode using SDL has it set up with two different bitmaps, one for OpenGL stuff and one for the SDL 2D stuff. You should have a look through that.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!