Sign in to follow this  

help needed, show you screenshots

This topic is 4854 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

Reading your small blurb at the bottom, I really feel you should try and learn either OpenGL or DirectX. Being able to do what you did without them is impressive, but you'll be solving all the problems that many others have already solved.

One example is your polygon sort problem. Actually hardware has a Z-buffer for that, and it's built in, and fast. You seem to have enough programming and math background, that learning one of these API's should be relativley simple to do. In a month or two, you should be able to re-create that system, and made it 1000% better.

Still I'm impressed you did that without an API of any sort.

Share this post


Link to post
Share on other sites
thanks for that. right now, i'm developing the game system. another problem is that i've only got a month left, and i have three other programming projects. =< if i have time, i would really study openGL. right now, i think i'll get on with it.

thanks for the reply.

Share this post


Link to post
Share on other sites
Actually, I'd kind of disagree with the idea of learning a 3D API. You'll learn much more without using one.

Incidentally, use the mergesort algorithm to sort your polygons - it's a little slower in the quicksort's best case (in order) but doesn't have quicksort's worst case (takes longer than bubble sort due to being more complicated).

You might like to take a quick look at Java3D. It's Java, it's a scenegraph (camera here, light here, planet here, moon here, moon rotates around planet, run, ooh pretty.). It's hardware accelerated (via OpenGL [the creators really make their preference to OpenGL clear] or DirectX. Whether you use OpenGL or DirectX is completely up to the Java3D runtime you install, and is transparent to your application.). It's cross platform. You can import 3D models (export is near impossible). It's pretty cool and reasonably easy to use. I'm not entirely sure it really has a future though.

What you've got is impressive. What you need to do is finish.

If it's a school rather than a university, I'm impressed that they don't think Computing stops with MS Access.

Share this post


Link to post
Share on other sites
Writing your own 3D rasterizer is cool and everything, but it's not very practical for a finished product. If you're interested in learning all of the math then go ahead and continue it, but I would suggest finding a Java OpenGL wrapper you like and learning that as well.

Share this post


Link to post
Share on other sites
so what is openGL really like? with VC++, i don't quite get it. I'm confused with what kind of objects are passed in it (parameters), is it just a collection of functions or objects... the reason why i made my own is that i can be flexible with it because i understand how it works.

may be with a little study, i can get on with it. plus there's not much resources concerning java using openGL. it's still in its underground state. more people are still using c++.

if you don't mind, i would like to talk about my stuff. maybe by then, you could give some suggestions.

i have these basic objects that make up my system.

Vector3D //an x,y,z values holder

Vertex //holder of three vectors (local, world, aligned)

Matrix //basic scaling, translating, rotating

Edge //holds two ints, each int is an index to the array
//of vertices. As you can see with the wireframe.

Triangle //holds three ints, each is an index to the array of
//edges

Object3D //holds the array of vertices, edges, triangles
//also holds vectors for scaling, position(translate)
//and rotation

Camera //holds three vectors for zooming, camera position
//and camera rotation

This is basically it. The rendering is as follows. I only need one matrix for the whole procedure. It's basically straightforward.

-get identity matrix
-scale matrix with the object's scaling vector
-translate matrix with the object's position vector
-rotate matrix with the object's rotation vector
-get the world coordinates of each vertex by transforming the local vectors using the current matrix

So I now have world coordinates. Next is the aligned. Same procedure, only that I will use the camera vectors this time.

-get identity matrix
-scale matrix with the camera's zooming vector
-translate matrix with the camera's position vector
-rotate matrix with the camera's rotation vector
-get the aligned coordinates of each vertex by transforming the world vectors using the current matrix

Then I will have to get the array of 2D projection points of each aligned vertex using the basic equations, x = v.x / v.z and y = v.y / v.z. Basically, the ints that each edge hold would also refer to the same index in the array of 2D points. Same is true with each triangle ( triangle -> edge -> vertex ). All i have to do then is to get three distinct points from the triangle. Once i got the three points, i'll get z - deth. This is then where i'll have to sort the triangles using quick sort. Apply shading to its color. Then I'll draw it with a simple function in Java, g.drawPolygon( { p1.x, p2.x, p3.x }, { p1.y, p2.y, p3.y } );.

That's all there is to it. Of course there's some lacking stuff like texture mapping, clipping, many others... But if you can in any way get what it does and optimize it, please share it with me.

Share this post


Link to post
Share on other sites
OpenGL really does no more than replace the rasteriser. It will do matrix transforms, but, if you need the results within your application, then you have to implement some functionality in this department.

I assume you are using g.drawFilledPolygon(x, y, 3); to draw each triangle?

If so you probably now have something like:


public class MainApp {
//stuff
void paint(Graphics g) {
Object3D object;
// sort objects
Iterator iter = orderedobjects.elements();
while(iter.hasNext()) {
object = iter.getNext();
object.paint(g);
};
}




public class Object3D {
//stuff
void paint(Graphics g) {
int x[] = new int[3];
int y[] = new int[3];
Face face;
// transform vertices
// sort faces
Iterator iter = orderedfaces.elements();
while(iter.hasNext()) {
face = iter.getNext();
x[0] = vertices[face.xvertex[0]];
x[1] = vertices[face.xvertex[1]];
x[2] = vertices[face.xvertex[2]];
y[0] = vertices[face.yvertex[0]];
y[1] = vertices[face.yvertex[1]];
y[2] = vertices[face.yvertex[2]];
g.drawfilledPolygon(x,y,3);
};
}



With OpenGL you could something like the following (from memory):


public class MainApp {
//stuff
void paint(Graphics g) {
Object3D object;
// NO NEED TO SORT OBJECTS
glBegin();
// set view transform
Iterator iter = unorderedobjects.elements();
while(iter.hasNext()) {
object = iter.getNext();
object.paint(g);
};
glEnd();
}




public class Object3D {
//stuff
void paint(Graphics g) {
int x[] = new int[3];
int y[] = new int[3];
Face face;
// NO NEED TO SORT FACES
// set model transform
Iterator iter = orderedfaces.elements();
glBegin(GL_TRIANGLES);
while(iter.hasNext()) {
face = iter.getNext();
glVertex3f(vertices[face.xvertex[0]],
vertices[face.yvertex[0]],
vertices[face.zvertex[0]];
glVertex3f(vertices[face.xvertex[1]],
vertices[face.yvertex[1]],
vertices[face.zvertex[1]];
glVertex3f(vertices[face.xvertex[2]],
vertices[face.yvertex[2]],
vertices[face.zvertex[2]];
};
glEnd();
}



It's not the fastest way (eg., loading the object into a vertex array and using that may be faster).

Share this post


Link to post
Share on other sites
It uses what's called a "z-buffer," which is a buffer that encodes the depth of every fragment. Before a new fragment is combined with the color buffer, it is (optionally) first checked to make sure it passes the depth test. Generally, the depth test is set up so that fragments that are behind (have a depth further than) the current fragment are discarded.

Share this post


Link to post
Share on other sites
At it's core you give OpenGL a modelview matrix (transforms model to world space), a projection matrix (transforms world to screen space) and then a series of lists of stuff to draw (triangles (individually, strips or fans), quads, lines, points or a polygon.

The lists include all the data about position, colour, texturing etc., OpenGL can also do lighting for you (you have to help it with shadowing though).

Share this post


Link to post
Share on other sites
im working towards something similar. If you use a bufferedimage and get the pixel data as an array you can write your own poly filler with gouraud shading and it wont be to much slower. What frame rate are you getting now?

Share this post


Link to post
Share on other sites
The primary advantages of a software renderer are that it needs fewer libraries and is more portable. Unfortunately, it tends to be slower and lower quality than hardware (speed tradeoff). It also can take a long time to write. I've personally found that you can easily spend a week just messing around getting it to work, particularily if you are using sub-pixel precision - which looks better - compare the original Quake's world rendering with the monsters for some idea.

Share this post


Link to post
Share on other sites
I've done the same thing, making a 3D renderer, but with textures, smooth shading and Z-buffering I couldn't get it to run at more than 20 FPS, and this is not enough to make really nice effects. I converted to using JOGL, a Java wrapper around OpenGL. It's quite easy to pick up once you've created your own renderer. For tutorials, I recommend the Red Book, and NeHe (many lessons have JOGL versions downloadable at the bottom of the page). It's fairly simple to convert any C++ tutorials you find; the only big difference from C++ is that you must use direct-mapped ByteBuffer objects in places where you would use pointers in C++; these can be created easily with the net.java.games.jogl.util.BufferUtils class.

Share this post


Link to post
Share on other sites
Yes, the Red Book (Programmer's Guide) is excellent. (Up to Fourth Edition now IIRC). If you are feeling flush with cash, there's the Blue book (Reference) - which I don't own - and the Orange book (Shaders) - this is quite advanced (get familiar with the basics first!) and the shaders are applicable to I think OpenGL 1.5+ (Radeon 9800/Geforce FX hardware) upwards.

Share this post


Link to post
Share on other sites
so much for openGL stuff. i know they're really great. i've added some libraries in my jdk. i got java3D and lwjgl. i still have to find out which works better. if jogl would prove better, maybe i would look for that, too. so, which is which, java3D, lwjgl, jogl?

i've got a problem working with visualizations. something like casting spells, adding dynamic visuals for it. with my system, vertex -> edge -> triangle, it's really hard. i have to work with some equations, like making a sphere, enlarging it, then it bursts, damaging anything surrounding it... or work with lightnings and thunder. if you have ideas on how to do it, please share it with me.

thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by davenirline
so much for openGL stuff. i know they're really great. i've added some libraries in my jdk. i got java3D and lwjgl. i still have to find out which works better. if jogl would prove better, maybe i would look for that, too. so, which is which, java3D, lwjgl, jogl?

After having used all of them quite a bit:
- Java3D is a scene-graph library, which means you deal with things on a much higher level. Geometry objects, camera objects, etc. and let it do the rendering for you. Nice but not really very flexible for games since you'll find yourself fighting against it rather than with it most of the time.
- Jogl is still very buggy, especially on different bits of hardware. No fullscreen support.
- LWJGL is much more reliable. Like Jogl its direct access to OpenGL (so much more low level and no scene graph). Fullscreen support that works. Dead easy to setup and use. :)

Share this post


Link to post
Share on other sites
lwjgl tutorials is very hard to find. looking at some source codes, i guess i still have to learn openGL. what i'm really looking for is the basic recipe in a java app to get it to work, especially about the basic objects to use.

could someone guide me to a good lwjgl tutorial? once i get the hang of it, i can adjust easily.

thanks again.

Share this post


Link to post
Share on other sites
Nehe has LWJGL and JOGL code. What may really help is getting a book like the OpenGL Bible or the Red Book and getting an understanding of OpenGL first. Then, lookin at examples that come with LWJGL and JOGL, combined with Nehe should help you.

And to be honest, right now, OpenGL and LWJGL have little different, except that LWJGL is OO, so you prefix all the commands with GL.

A good community for both libraries is http://www.javagaming.org.

Share this post


Link to post
Share on other sites

This topic is 4854 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this