C++ vs Java for simple graphics [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I want to develop a program that topologically sorts the vertices of a directed graph as a way to practice some of the graphing data structures and algorithms I'm learning in algorithms class. To make things a bit more interesting, I also want to add some graphics to display the results of the topological sort, something like in image b) below.
I'm familiar with the basics of both C++ and Java, so I'll be choosing one of those languages to work in. First, what are the pros and cons of working in each language for a project like this? Second, what kind of libraries should I look at to implement these kinds of simple graphic? I know that there are lots of choices out there, but I'd like to choose something that I might use again in the future and isn't total overkill for a task like this.
Thanks

I would certainly prefer Java over C++. yes C++ is core but Java provides over 30,000 classes and interfaces. you get the Graphics class in awt package.
Graphics class is the abstract base class for all graphics contexts that allow an application to draw onto components that are realized on various devices, as well as onto off-screen images.
The Graphics class plays two different but related roles within the abstract windowing toolkit (AWT). First, it maintains the graphics context, which consists of all of the information that will affect the outcome of a graphics operation. This includes the drawing color, the font, and the location and dimensions of the clipping rectangle (the region in which graphics can be drawn). More importantly, the graphics context defines the destination for the graphics operations about to be discussed (destinations include components and images).
All the best

Related

Is it better to reuse the same instance of awt.Graphics than to create copies with Graphics.create()? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I got involved with some folks making a new 2D game engine in Java, and I got curious when I learned they avoided using any variation of Graphics.create in their engine's code.
When asked, they said they feared making copies of Graphics for every graphical component seemed like "(...)quite some amount of overhead."
But they could not provide any proof of the claim. Instead of making use of the clipRect and translation properties of Graphics, they instead provide their own support API for drawing in the right place.
I'm not a part of their team, but I do use their unfinished engine in my own project, so I want to find out.
Looking for an answer myself resulted only in a brick wall. The Graphics class is abstract, and I have so far not found any implementation code. So I can't find the answer.
And so I end up asking here.
What performance/memory cost if any, is there for using the Graphics.create() function?

object oriented design in java | Libgdx methods [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This question is relatively easy to answer but i don't really know the answer as i have no real experience with java or libgdx.
Question: I would like to know the most effiecent way to orginize code in java, i have a strong background in php and in my php projects i would use several different php files (think of it as a class) and just reference it in my main page using either "include 'filename'; or require 'filename'; " . I would keep my header.php, content.php and footer.php completely separate and just reference it. This was a very nice method for me as it really kept my code organized.
What i want to know is if there is an easy way to do this in java/libgdx? i am currently making an android application and as you may know there are life cycles such as create(); render(); resize(); etc.
What i had in mind was to put each cycle e.g. create(); into a class of its own and use extends in my main class. Will this even work?
Thanks for any help in advance guys, its really bugging me to have so much of my code in one main class.
The question is very abstract, and you can read lots of books or articles about OOP, design patterns and code styling, so I will just give few practical tips:
You can use MVC pattern. Create three packages yourpackage.view, yourpackage.model, yourpackage.controller and split your classes by this model.
You can create package yourpackage.utiles and put there all classes with only static methods, which are used in all your app.
Don't put too much code into one class, Java is very objected oriented. Very simple example: you have game with 4 screens. You should create parent Screen class, 4 classes which will be extended from Screen for every screen and class ScreenManager which will change screens.
In game dev Singleton is very useful pattern. You can use it for GraphicMangaer, charcter progress holding, dpad controller, etc.
About your question, there is no reason to put create() method into your classes, constructor is enough. What you can do is to create draw() method in every class which draws something and put there all logic of drawing. Then you can just call draw() methods of your classes in your screen render() method.

Use Java Graphics2D vs JOGL [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm getting into learning Computer Graphics with Java. I was wondering, should I learn Java2D before learning JOGL, or should I just learn JOGL (which handles 3d graphics as well)? This (I hope) isn't an opinion based question in the sense that I'm looking for a correct path to follow. I guess, put another way, my question is: what is the point of having the Java Graphics 2D library if JOGL is around?
Note: my final goal is to be able to develop Graphics for business applications.
It's not entirely clear what you mean by "business applications". You're not talking about the "computer game business", are you? ;-)
Seriously: Nearly every question of the form "Should I use X or Y?" has the same kinds of answers:
"That depends on what exactly you want to do" and
the subjective ones.
The Graphics2D class is a rather high level abstraction, and with a few lines you can do your first custom painting operations. And they are intuitive. You want to draw a line with Graphics2D? Well, call graphics.drawLine(0,0,100,100);. You'll quickly have a feeling of success. The basic code to get started is conveniently summarized in http://docs.oracle.com/javase/tutorial/uiswing/painting/ , and with the knowledge from http://docs.oracle.com/javase/tutorial/2d/geometry/index.html and some phantasy you can already achieve nice effects.
OpenGL is a different world. First of all its focus is 3D graphics, and this is not "just a superset of 2D". While you technically can do 2D graphics with OpenGL as well, that's not what it was made for. It's much closer to the hardware, tailored for high-performance management of large 3D objects with powerful (and complex) rendering techniques. You want do draw a line with OpenGL? Well, if you want to do this with pure, modern (!) OpenGL, it will involve maybe 100 lines of code, including your own shader programs that are written in GLSL. And without a profound background certain fields of mathematics and graphics cards, and without a reading elaborate tutorials or books (like http://arcsynthesis.org/gltut/ ), you'll hardly be able to bring anything to the screen at all.
So to summarize it, concerning your actual question:
what is the point of having the Java Graphics 2D library if JOGL is around?
If you want to create some 2D drawings, maybe some bar-, pie- or line charts, and maybe a few images, you simply would not use OpenGL due to its complexity. Java2D is part of the standard API, and it is tailored for things like this (although, of course, there are still different more specialized libraries for different purposes). If you want to do anything that goes beyond 2D, or employ some really sophisticated rendering effects, you'd have to use OpenGL.

Java/Slick - Should I use multiple classes for a game [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hello i'm new to slick (and lwjgl) and was wondering if its best to stick to one class or multiple when I used straight java I used multiple classes but wasn't shoure about slick
Please do use multiple classes. Classes keep things organized, and it is easier to document. Also, you can use an ArrayList to have a lot of class instantiated and use them later on. The most important thing about multiple classes is that it is organized. It is hard to use only one class for a game, because there will be a lot of code, and you need to try to pack together everything. Use multiple classes!
Java is an object-oriented language for a reason, and classes are there to help you. Using multiple classes will allow you to break down the game logic and view it as the interactions between objects of different classes, limiting complexity and making the game easier to understand. I'm not sure what kind of game you're writing, but for example, you could have a Player class, of which the active player is a member, tracking things such as health or lives, position on screen, et cetera. The player object could then interact with objects of class Monster, Wall, Door, Chest, so on and so forth.
Using classes allows you to reuse code and avoid repeating yourself, manage the complexity of the project, and encapsulate logic. When you're working in Java, an object-oriented language, it'd be wise to try and write code that follows an object-oriented paradigm.

jumping form Java to C [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Ok I gave been playing around with java for a year now an I can say that is is in my power to write a fully functional program.
A month ago I started studying vectors and so, when I tempted to implementing them into the LWJGL I realized that Java is not fast enough for the level of graphics that I wish to generate.
Now that is my problem and I have decided that I must learn a stronger Language but where do I begin I have tinkered around in C/C++ before but it kills my ambition to go and start over after already using a hole year.
my "algors" for rendering a vector are:
z = r(cos t+j sin t) //where the t is degrees and r is its length
(for the curious)
the program the continues a loop that alters its length with 1, gets its end X and Y and draws a pixel on that spot.
Not for game coding.
Name 1 free E-Book that will get Me on My feet with C
I realized that Java is not fast enough for the level of graphics that I wish to generate.
Java is plenty fast. Unless you want to work with high performance graphics, you can use it safely (and you will probably be able to use it even with high performance graphics).
In the vast majority of cases, the speed of your application will be a function of algorithmic complexity, not language used.
After your application is completed, if it doesn't run fast enough, you can optimize. If it still doesn't run fast enough, you can implement critical parts in C/C++/your-language-here.
If you start from "the language is not fast enough", you're already doing it wrong.
If you want to write a game, use an engine. There are many great engines in many languages. If you wonder about language-inherent performance, and you try to solve technological issues yourself, you are gonna be stuck doing that forever.
Do not reinvent the wheel. Stop worrying about which programming language is the best fit, and rather think about which engine is best suited for what you want to make.

Categories