Programming fake 3d using sdl?

Started by
11 comments, last by workaround 9 years ago

[Solved] this topic is solved to what I wanted as an answer. Is it worth it to make 3d game with out openGL. This game is mostly 2d. It seems it is not worth the time if it potentially may require higher CPU model.

I'm interested in using sdl to make a make a ground plane that works like in sonic the hedgehog 3 bonus levels(Link bellow). I'm not interested a 3d environment like opengl on top of sdl.

I want to know if it is possible to take a image and distort the image so it looks like it is on the ground. The viewer would always be at the same angle link in the link bellow.

Advertisement

I'm fairly sure that in that particular instance, they've basically just rendered one 90° rotation animation and one "walk one tile forward" animation of the checkerboard, de-duplicated it into a tile map to save video memory, and are just playing those two animations with palette swapping to set the colours. And because will only need to have rendered the checkboard animation once, every time the player makes a full step forward, they swap the two colours of the checkboard palette so they can continue to use the same animation frames.

If you want the same basic effect on a more complex map (e.g. an arbitrary tilemap, instead of a featureless checkerboard), you're probably best off using a single-object raytrace-like projection. You can save CPU time and reduce rounding-error-induced aliasing by pre-calculating a projection of your viewport to the on-map coordinates to sample each pixel from (giving a lookup table of 2 floats per screen pixel), and then applying translation and rotation to those relative offsets from the camera. Use the inverse of that projection function to project sprite objects into camera space.

Do you have a specific reason for not wanting to use OpenGL? A self-imposed limitation to experiment with a technique is just fine, but if you're of the mind that OpenGL isn't worth learning to do this, you might want to reconsider.

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

Wyrframe is pretty much dead-on.. Keep in mind that an actual 3D solution would be more difficult than actually having a sphere, because you can't actually map a checkerboard texture to a sphere in 3D space.


Do you have a specific reason for not wanting to use OpenGL? A self-imposed limitation to experiment with a technique is just fine, but if you're of the mind that OpenGL isn't worth learning to do this, you might want to reconsider.

Raytracing seems to close to what I was looking for. Because I have not done this before I did not know what to search. Now that I have done just a little bit of searching it seems that using raytracing in a video game is not a good choice unless everyone is using a server farm to play the game.

Now I'm getting into some opengl questions(yes and no are not what I'm looking for). I would like to know the api calls or a link to tutorial would be nice.

1. Can I map a png to a plain in opengl and still have transparency?

2. Can I map only a portion of a image to a plain?

1. Can I map a png to a plain in opengl and still have transparency?
2. Can I map only a portion of a image to a plain?


1. Yes. Translucency is a part of the blending mode in use, the alpha channel generated in the fragment shader (which it will usually acquire from a texture), and whatever you drew first (OpenGL by itself does no sorting or painter's algorithm, so you want to be sure to draw whatever is behind the translucent object first).

2. Yes. It's up to the fragment shader to determine how to sample the texture. A typical pattern to supply texture coordinates (often called the "UV" coordinates) that inform the shader which region of the texture to sample. If you give texture coordinates from [0.5,0.5] to [1.0,1.0] on an otherwise 'standard' sampling fragment shader, you will only sample the bottom-right quarter of the texture instead of the whole thing, for example.

More advanced graphics effects are almost always possible as well, but may require some non-intuitive approaches or advanced math knowledge.

Sean Middleditch – Game Systems Engineer – Join my team!

I'm fairly sure that in that particular instance, they've basically just rendered one 90° rotation animation and one "walk one tile forward" animation of the checkerboard, de-duplicated it into a tile map to save video memory, and are just playing those two animations with palette swapping to set the colours. And because will only need to have rendered the checkboard animation once, every time the player makes a full step forward, they swap the two colours of the checkboard palette so they can continue to use the same animation frames.

Pretty close.

For turning, there are seven frames of animation, each frame turning 11.25 degrees (not including the cardinal direction frames).

Moving forward/backward also makes use of palette animation. The individual squares are broken up into 4 bands of color, and there are two frames, one offset by 1/8th of a square. So by alternating the two frames and adjusting the palette every second frame swap, the result is the appearance of moving in increments of 1/8th of a square.

Even after removing redundant tiles, the background images still take up nearly 3/4 of the system's VRAM.


Do you have a specific reason for not wanting to use OpenGL? A self-imposed limitation to experiment with a technique is just fine, but if you're of the mind that OpenGL isn't worth learning to do this, you might want to reconsider.

Raytracing seems to close to what I was looking for. Because I have not done this before I did not know what to search. Now that I have done just a little bit of searching it seems that using raytracing in a video game is not a good choice unless everyone is using a server farm to play the game.

Now I'm getting into some opengl questions(yes and no are not what I'm looking for). I would like to know the api calls or a link to tutorial would be nice.

1. Can I map a png to a plain in opengl and still have transparency?

2. Can I map only a portion of a image to a plain?

You might actually be looking for ray marching. You can more easily test intersections with objects (such as your plane) and use a fisheye-like projection to curve the rays to produce the sphere effect. Then animating the plane movement is as basic as off-setting through the X and Z directions.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

Now that I have done just a little bit of searching it seems that using raytracing in a video game is not a good choice unless everyone is using a server farm to play the game.
Hence why I mentioned pre-calculating the lookup projection.

Your camera, by the constraints you gave us, is at a fixed viewing angle, and a fixed distance from the "sphere" you want to move around over. The only object it is viewing is a single sphere, onto which you are going to project a small portion of a flat 2D map. So, you only have to do one frame worth of raytracing, and then remember the U,V coordinates that each on-screen pixel got cast to (or "none", if it cast to not intersecting with the sphere at all). To render each frame, you then walk the screen, read the U,V coordinate (or lack thereof) for each pixel, apply a translate/rotate matrix to that U,V coordinate (rotating around only the axis from the center of the sphere to your camera, so this is only a 2x2 or 3x3 matrix), and then sample the texel at that coordinate of your map. This would be very cheap as a fragment shader applied to a single full-screen quad.

It's not real-time ray-tracing, because you're not performing a full scene traversal and lighting analysis every pixel, every frame. Your "scene" is actually static; an unmoving sphere and an unmoving camera. You'll be doing only a simple U/V transform for each pixel, each frame.

However, it is also sounding like you're quite new to graphics programming in general, not just OpenGL. You'll want to master a simple flat 2D tilemap first, then try projecting a view of it that is bent down at the edges to make it look like the map is curved onto a sphere. If you are already well-versed in shader programming, then you could probably dive straight in to the technique above, though.

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

and use a fisheye-like projection to curve the rays to produce the sphere effect

I'm not looking for a sphere effect. I want a flat plain. Thanks for the input. More information on what I'm doing the static camera angle, character position, having a small viewer of the sky, the ground needs to give the view the feeling they are moving. I'm not using box texture I will use grass and others.


However, it is also sounding like you're quite new to graphics programming in general, not just openGL.

That is correct. I'm developing on Linux so OpenGL is the best option if I need it. I was hoping that something like this would make sense to do with out openGL.

You want a flat plane? So, something akin to this, at 12m15s;

#t=12m15s ?

That's vastly easier. Look up just about any OpenGL tile map drawing. I also encourage you to learn how to use a VBO early, before you learn any bad habits that immediate mode encourages.

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

This topic is closed to new replies.

Advertisement