Need help backwards learning! Newbie

Hello to anyone reading this, I hope your day is going well so far.

I am what some would call a “n00b” trying to get my feet wet in Java programming for the first time at age 26 and was looking to the community for help with an error I have not been able to work around. I should say I have programming experience in lesser languages (BASIC, Visual Basic. HTML) but i haven’t done much in a long time so I am a bit rusty. ( I don’t think that really helps much in this case anyway)

I downloaded a project from GitHub at: Git Repo used called World of Voxel and have basically been backwards engineering it to work properly in the JDK. I chose this project not to make a Minecraft clone but because I feel the type of mechanics used will be a great way to learn a lot of different things without worrying about a model heavy application. Once I am done learning I can start my own projects.

I am not 100% sure if this code is fully compatible with JMonkey which is kind of where the pro’s come in so if you could either take a look at the link or I can paste any of the code on this forum to show you what has been done so far. In this project I am not calling upon SimpleApplication at all and the only libraries I am using are included with the file, lwjgl.jar and lwjgl_util.jar. After looking at it I think the issue has to do with ‘image’ never being defined but I can’t tell for sure. Here is the first function know has an issue:

[java]public static int createTexture(BufferedImage image){
int[] pixels = new int[image.getHeight() * image.getWidth()];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());

	ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL);
	
	for(int y = 0; y  16) & 0xFF));     // Red component
                buffer.put((byte) ((pixel >> 8) & 0xFF));      // Green component
                buffer.put((byte) (pixel & 0xFF));               // Blue component
                buffer.put((byte) ((pixel >> 24) & 0xFF));    // Alpha component. Only for RGBA
            }
        }

        buffer.flip();
	
	int textureID = glGenTextures();
	glBindTexture(GL_TEXTURE_2D, textureID);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
	glBindTexture(GL_TEXTURE_2D, 0);
	return textureID;
}

}[/java]

The line that starts int[] seems to error out specifically.

I appreciate any information to help me figure this out and I’ll do my best to keep up with your answer.

No offense, but reverse engineering an application to learn a language sounds like the worst learning strategy to me.
That’s a nightmare even when you are a seasoned programmer so you’ll get either bored or mad.

My advice is to start by learning java, http://www.javabeginner.com/
Shuffle through it if that looks too easy, but read it. There are a lot of concepts in Java that are not in Basic, VB or HTML.
Then think of your own project, a simple one. Box world are a lot more complicated that it seems, and that’s not what I would recommend for a beginner.
Once you get a bit hot, go through the JME tutorials https://wiki.jmonkeyengine.org/legacy/doku.php/jme3 to grasp how things works in JME.
Then start with your small project.
You will discover many things, learn a lot, and in the end maybe you’ll be ready to start the “real” project that you already have in mind today :wink:

About that method, first please use the code tag (the sheet with the 2 sharps) on the forum when you paste code, it’ll be a lot easier to read and avoid that your code is replaced by occasional " 8) ".
The JME API is at higher level than this method, and you’ll never have to use things like that, especially those direct gl calls.
There could be many reason why this method fails and you didn’t provide enough information for us to help, the actual exception to begin with.
The best practice when you have an error, is to post the exception. I know java exception looks gibberish for a beginner, but it does provide very useful information.
If it’s really the line you say that fail, my bet is for a NullPointerException on image. Your BufferedImage has not been properly initialized, maybe you had an issue at loading…a path issue?
But really that’s a blind shot and very far fetched.

2 Likes

What Nehon said :slight_smile:

Also HTML is not a programming language…

I couldn’t agree more. Monkey see - monkey do just will not pan out at all and really just cause confusion, as Remy said even for seasoned programmers.
Its even better to try and make a box world out of boxes first to then find out it doesn’t work that way and work your way up. Also, and please believe us, you will be faster that way.

I corrected the code tag, that was my fault since I assumed the word code in brackets is how the forum was setup…

Aside from the HTML isn’t a language remark which added zero value and was intended to just make me feel stupid I appreciate the resource recommendations. I’ll take a look at the resources suggested in order to figure out why that line is causing an error. Cheers.

It’s not intended to make you feel stupid. It’s a friendly pointer to the difference between HTML (a markup language) and the others (programming languages). Stuff relevant to HTML is not relevant to programming, and vice versa.