Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[java] Java Graphics


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Kosh   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2000 - 04:38 AM

Hi everyone, I am trying to program a little 2d application in java, just something that plots pixels to a screen. I want to recreate my good ol days with the spinning cubes, but I am unsure about how I should plot pixels in an efficient manner, I know about the Point2D class, but I would like to know, is there a better way of doing this. If you know anything that can help me please do tell me thanks Kosh

Sponsor:

#2 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2000 - 04:59 AM

You may want to check out the following book:

Java 2d API Graphics with Cdrom
Vincent J. Hardy
ISBN: 0130142662
Publisher: Prentice Hall
Pub. Date: August 1999
Edition Desc: BOOK & CD

Its one of the few decent books for Java and Graphics that I have found.

Also, I know you said you wanted to use 2D, but you may want to consider Java 3D as well. The example you quoted - creating spinning cubes - could be accomplished in just a few lines of code (in fact, one of the demo programs that comes with Java 3D is a mouse controlled spinning cube).

#3 Kosh   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 March 2000 - 10:39 AM

I know perhaps Java3D is a better choice, but I am trying to create a rendering engine, so using someone else''s 3d engine isnt a way that I would like to proceed, therefore, 2d is only open to me

do you have any online links ? cause I dont want to buy ANOTHER java book only to find that I didnt really need it.
spent too much money to do that mistake again....

thanks

#4 Captain Goatse   Banned   -  Reputation: 100

Like
Likes
Like

Posted 11 March 2000 - 08:04 PM

Buy The Black Art of Java Programming! It uses java 1.0 but all out-of-date code is very easy to change to java 2. Yes it explains how to create 3d engine, which had constantly 60 fps, but in 300x400 applet

Time comes, time goes and I only am.

#5 Kosh   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 March 2000 - 04:38 AM

ok, sorry to say this, but saying "buy this book" and "buy that book" is not what I want help with, I know I can buy this and that, but I dont want to buy another java book, I have four already, I want somewhere on the web that can help me, I have followed the advice of people before, spent over £150 on books in java and all of them have been a disappointment so therefore I wont buy another java book, cause I dont think they are worth it.

Can someone please suggest anything else other than "buy this book"

thanks.

kosh

#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 March 2000 - 04:54 AM

ok, sorry to say this, but saying "buy this book" and "buy that book" is not what I want help with, I know I can buy this and that, but I dont want to buy another java book, I have four already, I want somewhere on the web that can help me, I have followed the advice of people before, spent over £150 on books in java and all of them have been a disappointment so therefore I wont buy another java book, cause I dont think they are worth it.

Can someone please suggest anything else other than "buy this book"

thanks.

kosh

#7 Captain Goatse   Banned   -  Reputation: 100

Like
Likes
Like

Posted 12 March 2000 - 06:24 AM

I have bought 4 books too, and not even single one of them were disappointment. I have Sams book 21 hours or 24 days it was the first one. Then I have little manual for Java 2 which is extremely handy because it's so quick to recollect and cheat things out from it. Then I have this Black Art book and some kind of book which is written in my mother tongue. I'm sorry, but what I have looked there are very little things on we from Java Game programming. There are ready made engines, but that wasn't what you were looking for, but if you want see one go to the JGDC home page (www.jgdc.com) and check code section, if you look enough those examples and then put all you have found together I'll bet that you have ready 3d engine ready before you can say cheese! At least that would be the way that I'd do it

Time comes, time goes and I only am.

Edited by - Arch@on on 3/12/00 12:27:19 PM

#8 Kosh   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 March 2000 - 10:44 AM

lovely, I''ll check that out, thanks

#9 javanerd   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 March 2000 - 01:08 AM

Let me get this straight, you want to plot pixels to a screen? If by a pixel you mean a real pixel of size 1x1, then maybe you should familiarize yourself to the usage of an animated MemoryImage source. That technique is largely used in Java demos and should be quite fast (at least it is much faster than plotting hundreds/thousands of points through Graphics object).

The downside is that you''ll have to calculate all the transformations by yourself (calculate the screen x,y coordinates from world coordinates).

The technique is simply:
1) During initialisation create an integer array of size (screen width x height) and use that array to create an java.awt.image.MemoryImageSource and create an image from that. Set the memory image to be animated by calling the setAnimated(true) on it.


int[] pixels = new int[ width * height ];
MemoryImageSource memImageSrc =
new MemoryImageSource(
width,
height,
ColorModel.getRGBdefault(),
pixels,
0,
width );
memImageSrc.setAnimated( true );
Image theWholeScreen =
Toolkit.getDefaultToolkit().createImage(
memImageSrc );


2) You modify the individual pixels by setting the integer arrays values to wanted pixel values.


// Set pixel at x,y coordinates to red
pixels[ x + y * width ] = 0x00FF0000;


3) You tell the memory image source you have changed the pixels in the memory. Note: This should really just update the changed area, not the whole area as I have done here.


memImageSrc.newPixels( 0, 0, width, height );


4) You paint the image representing the whole screen to the graphics (in paint(Graphics g) or some other suitable way).


grfx.drawImage(
theWholeScreen,
0,
0,
null );


Hopefully this helps you getting started...

#10 Jim_Ross   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 March 2000 - 04:07 AM

There is also a good technique in "The Black Art of Java Game Programming" in which you use Shapes to plot "3D" images to the screen. Your spinning cube would just be 6 Shape objects and you would do the transformations and surface hiding manually. It is a good book, if you don't want to buy it, just go to the book store and thumb through it.

Also Kosh, your post about "spinning cubes" and "2d application" seem to be a bit contrary.

Edited by - Jim_Ross on 3/14/00 10:09:44 AM




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS