Skip to content

sinannar/GameEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# OPENGL Tutorials with Java

I am following this youtube series to implement this content in this repo
https://youtu.be/VS8wlS9hF8E

----------------------------------------------
#Video for setting up environment - Setting up a LWJGL Project ( https://www.youtube.com/watch?v=Jdkq-aSFEA0 )

watch the video, setup the environment, you need Eclipse and JDK then these followings 

LWJGL 2 download:
http://sourceforge.net/projects/java-...

Slick-Utils Download:
http://slick.ninjacave.com/slick-util...

----------------------------------------------
#Video 1 - OpenGL 3D Game Tutorial 1: The Display

LWJGL 2 tutorial series on how to create a 3D Java game with OpenGL!

Tutorial about setting up the project:
https://youtu.be/Jdkq-aSFEA0

Full code:
https://github.com/TheThinMatrix/Open...


Common Problems:

-In case you had annotations off, you need to do the ContextAttribs stuff all in one line like this:
ContextAttribs attribs = new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true);

-If you get the following error: org.lwjgl.LWJGLException: Could not create context (WGL_ARB_create_context) then your computer may not support the version of OpenGL that we're trying to use (version 3.2). Try removing the parameters from the Display.create() method and try again.

- Make sure you didn't miss the "!" in the "(!Display.isCloseRequested())" part.


LWJGL Wiki: http://lwjgl.org/wiki/index.php?title...

My Youtube Channel: https://www.youtube.com/user/ThinMatrix
Follow me on Twitter: https://twitter.com/ThinMatrix
Check out my game on IndieDB: http://www.indiedb.com/games/socuwan

----------------------------------------------
#Video 2 - OpenGL 3D Game Tutorial 2: VAOs and VBOs

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we learn how to render a model using VAOs and VBOs.

Here are the vertices that we used:

  float[] vertices = {
    -0.5f, 0.5f, 0f,
    -0.5f, -0.5f, 0f,
    0.5f, -0.5f, 0f,
    0.5f, -0.5f, 0f,
    0.5f, 0.5f, 0f,
    -0.5f, 0.5f, 0f
  };

Full code available here: https://github.com/TheThinMatrix/Open...
LWJGL Wiki: http://lwjgl.org/wiki/index.php?title... 
----------------------------------------------
#Video 3 - OpenGL 3D Game Tutorial 3: Rendering with Index Buffers

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we learn a more efficient way to render our quad using an index buffer.

Full code available here: https://github.com/TheThinMatrix/Open...

LWJGL Wiki: http://lwjgl.org/wiki/index.php?title... 


Common Problems

- Make sure that you use the new vertex positions array - it is different from last episode!

-In the loadToVao() method the last parameter of the RawModel constructor has now changed to "indices.length" instead of "positions.length/3". Make sure you've made this change!

-Creating the display must be the first thing you do in the main method. Don't try initializing the RawModel first.

If you get the " Cannot use offsets when Element Array Buffer Object is disabled" error, check the following:

-Check that you are calling the "bindIndicesVBO()" from the "loadToVao()" method.

-Don't unbind the index buffer anywhere! Each VAO has one special slot for an index buffer, and unbinding the index buffer will remove it from that slot.
----------------------------------------------
#Video 4 - OpenGL 3D Game Tutorial 4: Introduction to Shaders

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

So in this part of this week's tutorial I'll be explaining what Shaders do and how they work, and then in the next episode we'll be programming some ourselves.

LWJGL Wiki: http://lwjgl.org/wiki/index.php?title...
----------------------------------------------
#Video 5 - OpenGL 3D Game Tutorial 5: Coloring using Shaders

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

We put our knowledge of opengl shaders to use in this episode and create a shader program to color our quad.

Full code download (only use if you get stuck! You'd have no chance of understanding later tutorials if you skip this one!):
https://www.dropbox.com/sh/qtfhwru70y...

LWJGL Wiki: http://lwjgl.org/wiki/index.php?title...

LWJGL Download: http://lwjgl.org/download.php

Slick-Utils Download: http://slick.ninjacave.com/slick-util/
 

Common Mistakes:

-If you get a large access violation error then check that you aren't trying to initialize your shader before you've created the display. Creating the display MUST happen before you do anything else OpenGL related.

-Make sure that your "out" variable in the vertex shader has the EXACT same name as the "in" variable in the fragment shader.

-If you get the following error:  "'gl_Position' : undeclared identifier"
then check that you didn't load up the vertex shader code twice in the StaticShader. This error usually occurs when you load up and compile vertex shader code as a fragment shader.

-Make sure that in the MainGameLoop you render the quad AFTER starting the shader program but BEFORE stopping it. The shader program needs to be running when you render!

-In the ShaderProgram constructor make sure you're calling glAttachShader() for both the vertex shader and the fragment shader.
----------------------------------------------
#Video 6 - OpenGL 3D Game Tutorial 6: Texturing

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we learn how to texture models using opengl.

Common mistakes:

- If you get the "fatal" error that I get at the end of the video then check that you're storing the texture coordinate VBO in attribute 1 of the VAO and that you indicate that they are 2D coordinates (see 10:51 in the video)

-Make sure that your "out" variables in the vertex shader have the EXACT same pass as the corresponding "in" variables in the fragment shader. You can't call it "pass_textureCoords" in one and "pass_textureCoordinates" in the other.

-Make sure that the names of the "in" variables in the vertex shader are spelled correctly in the bindAttributes() method in the StaticShader class. 


LWJGL Wiki: http://lwjgl.org/wiki/index.php?title...
----------------------------------------------
#Video 7 - OpenGL 3D Game Tutorial 7: Matrices & Uniform Variables

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we learn about uniform variables and matrices.

Simple matrix maths: 
http://www.mathsisfun.com/algebra/mat...

Transformation Matrix: http://en.wikipedia.org/wiki/Transfor...

Euler rotations to matrix conversion: 
http://www.euclideanspace.com/maths/g...

More matrices:
http://www.opengl-tutorial.org/beginn...

----------------------------------------------

#Video 8 - OpenGL 3D Game Tutorial 8: Model, View & Projection Matrices

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week create a rotating 3D cube using model, view and projection matrices!

Full code download for this episode:
https://www.dropbox.com/sh/1glu6x4ajd...

Cube vertices: https://www.dropbox.com/s/xcq0xa3yqr4...

Projection Matrix Explained: http://www.songho.ca/opengl/gl_projec...

LWJGL Wiki:
http://wiki.lwjgl.org/wiki/Main_Page


Common Problems:

-Don't forget to multiply the transformation matrix with the vertex position in the vertex shader. This was shown at the end of the last tutorial.

-Calling the getAllUniformLocations() method: We did this in the last episode in the ShaderProgram class constructor, a lot of people leave this out accidentally.

- In the getAllUniformLocations() method make sure that you're setting the value of the "location_transformationMatrix" variable. Getting the location is not enough, you need to store it too!

-After adding the projection matrix your entity's z position needs to be more negative than -NEAR_PLANE, otherwise it will be outside the view of the "camera". Set your entity's z position to -1 like I did at 11:38 in the video.

-The order that you multiply the matrices together in the vertex shader matters! Matrices are not like normal numbers, and multiplying them together in a different order will give you a different result.

-The spelling of the uniform variable names: The names must be spelled EXACTLY the same in the StaticShader getAllUniformLocations() method as they are in the shader code.

-The projection matrix code: Double check the code for the projection matrix, I've had quite a few emails from people who have had errors, and it has ended up being a mistake in the createProjectionMatrix() method.

-When creating the transformation matrix make sure that you didn't copy and paste the 3 rotation lines and forget to change them for each axis. Make sure that it looks like this:
 Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1, 0, 0), matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0, 1, 0), matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0, 0, 1), matrix, matrix);
Check the vectors and the rx, ry, and rz!

----------------------------------------------
#Video 9 - OpenGL 3D Game Tutorial 9: OBJ File Format

An extra theory-only tutorial this week, just to stop the tutorial on Saturday from being too long. We'll be learning about the OBJ file format in this episode, and then on Saturday we'll program a parser that can load up models saved in this format into our game!

Download Blender for free: http://www.blender.org/download/
Download the stall model: https://www.dropbox.com/sh/7l598pr7b4...

----------------------------------------------
#Video 10 - OpenGL 3D Game Tutorial 10: Loading 3D Models

This week we create an OBJ parser to load 3D models made in Blender into our game!

Download the stall model: https://www.dropbox.com/sh/7l598pr7b4...

Download Blender for free: http://www.blender.org/download/

Common Problems:

-If you're using your own model then make sure to texture it in Blender first using UV mapping!

-The size of the normals array is "vertices.size() * 3" and NOT "normals.size() * 3". Check 6:38 in the video and make sure you got this right.

- Make sure your texture file has dimensions that are powers of 2 (128x128, 256x256, 512x512 etc.) The file may have got resized when you downloaded it.

-Make sure you used "1 - currentTex.y" in the processVertex() method.

-If you're using your own model and the texture looks distorted in the game but fine in Blender then you may be experiencing the texture seam problem that I talked about in the previous episode. You can fix this by using the improved OBJLoader provided at the end of episode 16.


----------------------------------------------
#Video 11 - OpenGL 3D Game Tutorial 11: Per-Pixel Lighting

This week we add per-pixel diffuse lighting to the game, making everything look that little bit more epic!


Common Problems:

- Make sure that you are calling bindAttributes() *before* glLinkProgram() in the ShaderProgram constructor. Also, check that you spelled the "in" variable names correctly in the "bindAttributes()" method in the StaticShader class.

-If your dragon seems to have lots of white and black patches then it could be one of 2 problems:

1. Your texture dimensions might not be powers of 2 (64x64, 128x128, 256x256 etc.)

2. If they are powers of 2 then try adding the following lines to the end of the loadTexture() method, just before returning the texture ID:
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);


Stanford Dragon Model: https://www.dropbox.com/sh/gscenjij7n...
Source: Stanford University Computer Graphics Laboratory

Vector maths basics:
http://www.bbc.co.uk/bitesize/higher/...

Dot product: 
http://betterexplained.com/articles/v...


----------------------------------------------
#Video 12 - OpenGL 3D Game Tutorial 12: Specular Lighting

Stanford Dragon Model: https://www.dropbox.com/sh/gscenjij7n...
Source: Stanford University Computer Graphics Laboratory

Vector maths basics:
http://www.bbc.co.uk/bitesize/higher/...

Dot product: 
http://betterexplained.com/articles/v...


Common Problems:

-Watch to the end of the tutorial! Quite a lot of people missed out the bit where I multiplied in the "reflectivity" variable.

- Make sure that you are calling bindAttributes() *before* glLinkProgram() in the ShaderProgram constructor. Also, check that you spelled the "in" variable names correctly in the "bindAttributes()" method in the StaticShader class.

-If your dragon seems to have lots of white and black patches then it could be one of 2 problems:

1. Your texture dimensions might not be powers of 2 (64x64, 128x128, 256x256 etc.)

2. If they are powers of 2 then try adding the following lines to the end of the loadTexture() method, just before returning the texture ID:
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

----------------------------------------------
#Video 13 - OpenGL 3D Game Tutorial 13: Optimizing

LWJGL tutorial series on how to create a 3D Java game with OpenGL!
This week we optimize our rendering system and add ambient lighting!
Stanford Dragon Model: https://www.dropbox.com/sh/gscenjij7n...
Source: Stanford University Computer Graphics Laboratory


----------------------------------------------
#Video 14 - OpenGL 3D Game Tutorial 14: Simple Terrain
(https://www.dropbox.com/sh/37h3ri1veomo53p/AACoUHiVpvfZfjuHs01CCfwTa?dl=0)
This week we program a terrain renderer and generate a simple flat terrain!

Code for generating terrain: https://www.dropbox.com/s/47qk4yrz5v9...

Full code download (try doing the tutorial first though!):
https://www.dropbox.com/sh/37h3ri1veo...


Common Problems:

-If you can't see the terrain make sure your camera is in the right position! It needs to have a y position of above 0, and if you still can't see the terrain then try turning the camera around by setting the "yaw" to 180.

-Make sure that you're starting and stopping the *terrain shader* (and NOT the static shader program) before and after rendering the terrain in the MasterRenderer's render() method.

-If the texture on the terrain only looks good in one corner then try adding these 2 lines into your loadTexture method before returning the texture's ID:
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

----------------------------------------------
#Video 15 - OpenGL 3D Game Tutorial 15: Transparency

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we add support for textures with transparency, allowing us to add loads of low poly plant-life into the game!

Models & Textures: https://www.dropbox.com/sh/oxq37wnc5a...

----------------------------------------------
#Video 16 - OpenGL 3D Game Tutorial 16: Fog

This week we implement 3D fog in OpenGL!

Improved OBJ Parser:
https://www.dropbox.com/sh/x1fyet1ote...

Models & Textures: https://www.dropbox.com/sh/4tmbdkkjba...
----------------------------------------------
#Video 17 - OpenGL 3D Game Tutorial 17: Multitexturing

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we implement texture splatting using blend maps in OpenGL!

Example Blend Map: 
https://www.dropbox.com/s/yfd7so1yg0f...

Models and Textures: 
https://www.dropbox.com/sh/m8y3g1bh1l...

----------------------------------------------
#Video 18 - OpenGL 3D Game Tutorial 18: Player Movement

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we implement some very basic player movement and jumping!

Models and Textures: 
https://www.dropbox.com/sh/i76qpo3ug7...

Yesterday's devlog video: http://youtu.be/pvTP0qs8Nlc

Basic Trigonometry:
http://www.mathsisfun.com/algebra/tri...
https://www.youtube.com/watch?v=F21S9...

----------------------------------------------
#Video 19 - OpenGL 3D Game Tutorial 19: 3rd Person Camera

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

3rd person camera movement this week!

Models and Textures: 
https://www.dropbox.com/sh/i76qpo3ug7...

Basic Trigonometry:
http://www.mathsisfun.com/algebra/tri...
https://www.youtube.com/watch?v=F21S9...

----------------------------------------------
#Video 20 - OpenGL 3D Game Tutorial 20: Mipmapping

LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we're doing mipmapping!

Models and Textures: 
https://www.dropbox.com/sh/ufem6k9nzb...

----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


----------------------------------------------
#Video  - 


About

Tutorial Implementation for OpenGL with JAVA

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages