Jump to content
  • Advertisement

Ali Aman

  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Ali Aman

  • Rank

Personal Information

  • Interests
  1. Heya. I am currently developing a 2D game engine using OpenGL and Java (LWJGL). I didn't follow any tutorials for this cause I have seen enough and want to implement this my self. I am currently at the font rendering stage. I used normal font texture atlases and fnt files to format the alignment of my text. It worked fine untill I scaled up or down the text. The texture was either blurry or pixelated. Thats when I found ThinMatrix tutorial on sign distanced fields and I implemented it and it works fine but... If you have watched it you know that he uses two floats (width and edge) which we can alter in order improve the anti aliasing of the font characters. The problem is he hardcoded in those values. That is what I don't want to do. I want those width and edge values to adjust according to font size. I have tried many formulas with it but none seem to work. If anyone can help me I will be glad to say thank you in return 👽👽. Thanks in advance
  2. I do mean vertex colors don't know Gouraud shading. Dunno submodel colors either.
  3. I want to load obj models in to my game with colors using Materials in Blender. I have an OBJ loader that just loads vertices, indices, texture coordinates, and normals using .obj file. But I want the OBJLoader to load colors as well as load colors using blender Materials which produce a .mtl file. And this should al be based on OpenGL 3.0+. I am using OBJLoader from ThinMatrix. Here is my OBJLoader.java. package renderEngine; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.List; import models.Model; import org.lwjgl.util.vector.Vector2f; import org.lwjgl.util.vector.Vector3f; public class OBJLoader { public static Model loadObjModel(String fileName, Loader loader){ FileReader fr = null; try { fr = new FileReader(new File("res/"+fileName+".obj")); } catch (FileNotFoundException e) { System.err.println("Couldn't load file!"); e.printStackTrace(); } BufferedReader reader = new BufferedReader(fr); String line; List<Vector3f> vertices = new ArrayList<Vector3f>(); List<Vector2f> textures = new ArrayList<Vector2f>(); List<Vector3f> normals = new ArrayList<Vector3f>(); List<Integer> indices = new ArrayList<Integer>(); float[] verticesArray = null; float[] normalsArray = null; float[] textureArray = null; int[] indicesArray = null; try { while (true){ line = reader.readLine(); String[] currentLine = line.split(" "); if (line.startsWith("v ")){ Vector3f vertex = new Vector3f(Float.parseFloat(currentLine[1]), Float.parseFloat(currentLine[2]), Float.parseFloat(currentLine[3])); vertices.add(vertex); }else if (line.startsWith("vt ")){ Vector2f texture = new Vector2f(Float.parseFloat(currentLine[1]), Float.parseFloat(currentLine[2])); textures.add(texture); }else if (line.startsWith("vn ")){ Vector3f normal = new Vector3f(Float.parseFloat(currentLine[1]), Float.parseFloat(currentLine[2]), Float.parseFloat(currentLine[3])); normals.add(normal); }else if (line.startsWith("f ")){ textureArray = new float[vertices.size()*2]; normalsArray = new float[vertices.size()*3]; break; } } while(line != null){ if (!line .startsWith("f ")){ line = reader.readLine(); continue; } String[] currentLine = line.split(" "); String[] vertex1 = currentLine[1].split("/"); String[] vertex2 = currentLine[2].split("/"); String[] vertex3 = currentLine[3].split("/"); processVertex(vertex1, indices, textures, normals, textureArray, normalsArray); processVertex(vertex2, indices, textures, normals, textureArray, normalsArray); processVertex(vertex3, indices, textures, normals, textureArray, normalsArray); line = reader.readLine(); } reader.close(); } catch(Exception e) { e.printStackTrace(); } verticesArray = new float[vertices.size()*3]; indicesArray = new int[indices.size()]; int vertexPointer = 0; for (Vector3f vertex:vertices){ verticesArray[vertexPointer++] = vertex.x; verticesArray[vertexPointer++] = vertex.y; verticesArray[vertexPointer++] = vertex.z; } for (int i=0;i<indices.size();i++){ indicesArray = indices.get(i); } return loader.loadToVAO(verticesArray, indicesArray, textureArray, normalsArray); } private static void processVertex(String[] vertexData, List<Integer> indices, List<Vector2f> textures, List<Vector3f> normals, float[] textureArray, float[] normalsArray) { int currentVertexPointer = Integer.parseInt(vertexData[0]) - 1; indices.add(currentVertexPointer); Vector2f currentTex = textures.get(Integer.parseInt(vertexData[1])-1); textureArray[currentVertexPointer*2] = currentTex.x; textureArray[currentVertexPointer*2+1] = 1 - currentTex.y; Vector3f currentNorm = normals.get(Integer.parseInt(vertexData[2])-1); normalsArray[currentVertexPointer*3] = currentNorm.x; normalsArray[currentVertexPointer*3+1] = currentNorm.y; normalsArray[currentVertexPointer*3+2] = currentNorm.z; } }
  4. Ok so your using the org.joml.Matrix4f where I was using org.lwjgl.util.vector.Matrix4f. Sorry my bad. Ok so now I am using the org.joml.Matrix4f. I just want to know where you call the method getWorldMatrix() in your code. Can you show me where you call that method? Thanks in advance!
  5. I think your not using LWJGL. Are you using JOGL?
  6. I have tried both orders but still it doesn't work. Here is the code for the transform: Matrix4f transformationMatrix = new Matrix4f(); javax.vecmath.Vector3f ballPosition = body.getWorldTransform(new Transform()).origin; Quat4f rotation = body.getWorldTransform(new Transform()).getRotation(new Quat4f()); transformationMatrix.rotate(rotation.x, new Vector3f(1, 0, 0)); transformationMatrix.rotate(rotation.y, new Vector3f(0, 1, 0)); transformationMatrix.rotate(rotation.z, new Vector3f(0, 0, 1)); transformationMatrix.translate(new Vector3f(ballPosition.x, ballPosition.y, ballPosition.z)); shader.enable(); shader.loadMatrix(transformationMatrix, "transformationMatrix"); shader.disable(); It can be what your saying. And I have tried all those solutions but it wouldn't budge. What I am surprised about is that there are very less resources on Bullet Physics with OpenGL >3.0. There has to be somewhere
  7. Unfortunately, It didn't work even when i tried rigidBody.getMotionState().getWorldTransform(...) I would really really appreciate if you would give me a link to tutorials on Bullet with modern OpenGL.. thanks in advance!!
  8. Yes, it is orbiting vertically--exactly the word I was looking for--and the speed of orbiting gets slower and slower until it stops. The object is keeping its shape but not rotating correctly.
  9. Ok, I rotated it before translating. I am getting some really weird results :0 the object is rotation really weirdly. I can't elaborate more than that. It is super weird.
  10. Yes, I did mean to include the source code but unfortunately forgot it. I'll paste it again so the problem is more clear. I got a bit updated with my code and moved onto modern opengl (>3.0). Every object is translating appropriately, but they are not rotating as they should. My problem is clearly in the code commented in the render() method. package renderEngine; import java.util.HashSet; import java.util.Set; import javax.vecmath.Quat4f; import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.util.glu.GLU; import org.lwjgl.util.glu.Sphere; import org.lwjgl.util.vector.Matrix4f; import org.lwjgl.util.vector.Vector3f; import org.newdawn.slick.Color; import org.newdawn.slick.TrueTypeFont; import com.bulletphysics.collision.broadphase.BroadphaseInterface; import com.bulletphysics.collision.broadphase.DbvtBroadphase; import com.bulletphysics.collision.dispatch.CollisionConfiguration; import com.bulletphysics.collision.dispatch.CollisionDispatcher; import com.bulletphysics.collision.dispatch.CollisionObject; import com.bulletphysics.collision.dispatch.DefaultCollisionConfiguration; import com.bulletphysics.collision.shapes.CollisionShape; import com.bulletphysics.collision.shapes.SphereShape; import com.bulletphysics.collision.shapes.StaticPlaneShape; import com.bulletphysics.dynamics.DiscreteDynamicsWorld; import com.bulletphysics.dynamics.DynamicsWorld; import com.bulletphysics.dynamics.RigidBody; import com.bulletphysics.dynamics.RigidBodyConstructionInfo; import com.bulletphysics.dynamics.constraintsolver.ConstraintSolver; import com.bulletphysics.dynamics.constraintsolver.SequentialImpulseConstraintSolver; import com.bulletphysics.linearmath.DefaultMotionState; import com.bulletphysics.linearmath.MotionState; import com.bulletphysics.linearmath.Transform; import abstracts.GameObject; import enums.ObjectID; import shaders.Shader; import tools.Utils; public class Game { public static Loader loader; public static BufferedImageLoader imageLoader = new BufferedImageLoader(); private static final Transform DEFAULT_BALL_TRANSFORM = new Transform(new javax.vecmath.Matrix4f(new Quat4f(0, 0, 0, 1), new javax.vecmath.Vector3f(0, 35, 0), 1.0f)); private Renderer renderer; private Shader shader; private Handler handler; private Camera camera; private static DynamicsWorld dynamicsWorld; private static Set<RigidBody> balls = new HashSet<RigidBody>(); private static RigidBody controlBall; private static boolean applyForce = false; private static boolean createNewShape = false; private static boolean resetControlBall = false; private static Sphere sphere = new Sphere(); private void setUpPhysics() { Transform DEFAULT_BALL_TRANSFORM = new Transform(new javax.vecmath.Matrix4f(new Quat4f(0, 0, 0, 1), new javax.vecmath.Vector3f(0, 17, -10), 1.0f)); BroadphaseInterface broadphase = new DbvtBroadphase(); CollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration(); CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration); ConstraintSolver solver = new SequentialImpulseConstraintSolver(); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); dynamicsWorld.setGravity(new javax.vecmath.Vector3f(0, -10 /* m/s2 */, 0)); CollisionShape groundShape = new StaticPlaneShape(new javax.vecmath.Vector3f(0, 1, 0), 0.25f /* m */); CollisionShape ballShape = new SphereShape(0.5f); MotionState groundMotionState = new DefaultMotionState(new Transform(new javax.vecmath.Matrix4f( new Quat4f(0, 0, 0, 1), new javax.vecmath.Vector3f(0, 0, 0), 1.0f))); RigidBodyConstructionInfo groundBodyConstructionInfo = new RigidBodyConstructionInfo(0, groundMotionState, groundShape, new javax.vecmath.Vector3f(0, 0, 0)); groundBodyConstructionInfo.restitution = 0.25f; RigidBody groundRigidBody = new RigidBody(groundBodyConstructionInfo); dynamicsWorld.addRigidBody(groundRigidBody); MotionState ballMotionState = new DefaultMotionState(DEFAULT_BALL_TRANSFORM); javax.vecmath.Vector3f ballInertia = new javax.vecmath.Vector3f(0, 0, 0); ballShape.calculateLocalInertia(2.5f, ballInertia); RigidBodyConstructionInfo ballConstructionInfo = new RigidBodyConstructionInfo(2.5f, ballMotionState, ballShape, ballInertia); ballConstructionInfo.restitution = 0.5f; ballConstructionInfo.angularDamping = 0.95f; controlBall = new RigidBody(ballConstructionInfo); controlBall.setActivationState(CollisionObject.DISABLE_DEACTIVATION); balls.add(controlBall); dynamicsWorld.addRigidBody(controlBall); } private static TrueTypeFont font; private static TrueTypeFont font2; private Game() { try { Display.setDisplayMode(new DisplayMode(1250, 660)); Display.setTitle("Game"); Display.setLocation(54, 32); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } } private void init() { setUpPhysics(); handler = new Handler(); camera = new Camera(new Vector3f(0, 17, 0)); loader = new Loader(); shader = new Shader("src/shaders/Vertex.glsl", "src/shaders/Fragment.glsl"); renderer = new Renderer(shader); GameObject.init(); } private void run() { while(!Display.isCloseRequested()) { render(); tick(); input(); } destroy(); } private void render() { renderer.prepare(); shader.enable(); Matrix4f viewMatrix = Utils.createViewMatrix(camera); shader.loadMatrix(viewMatrix, "viewMatrix"); sphere.setDrawStyle(GLU.GLU_SILHOUETTE); for(RigidBody body : balls) { javax.vecmath.Vector3f ballPosition = body.getWorldTransform(new Transform()).origin; Matrix4f transformationMatrix = new Matrix4f(); transformationMatrix.translate(new Vector3f(ballPosition.x, ballPosition.y, ballPosition.z)); // ^ this translates the object (of course) appropriately. I don't know how to work around rotation them. // I have tried doing transformationMatrix.rotate(...), it does rotate, but not properly. I don't know how to work around that :( shader.enable(); shader.loadMatrix(transformationMatrix, "transformationMatrix"); renderer.setColor(0, 1, 1, 1, shader); renderer.render(GameObject.cube, shader); } System.out.println(balls.size()); Matrix4f trans2 = new Matrix4f(); shader.enable(); shader.loadMatrix(trans2, "transformationMatrix"); renderer.setColor(0.5f, 0.5f, 0.5f, 1, shader); renderer.render(GameObject.rect, shader); shader.enable(); shader.enable(); shader.disable(); shader.disable(); handler.renderObjects(renderer); } public static void renderTTF(String text, int x, int y, Color color) { font.drawString(x, y, text, color); font2.drawString(-1000, -1000, "", Color.green); } private void tick() { camera.move(); handler.tickObjects(); dynamicsWorld.stepSimulation(1.0f/60.0f); Set<RigidBody> ballsToBeRemoved = new HashSet<RigidBody>(); for(RigidBody body : balls) { javax.vecmath.Vector3f position = body.getWorldTransform(new Transform()).origin; if(!body.equals(controlBall) && (position.x > -50 || position.x > 50 || position.z < -50 || position.z > 50)) { ballsToBeRemoved.add(body); } } for(RigidBody body : ballsToBeRemoved) { balls.remove(body); dynamicsWorld.removeRigidBody(body); } if (applyForce) { Transform controlBallTransform = new Transform(); controlBall.getMotionState().getWorldTransform(controlBallTransform); javax.vecmath.Vector3f controlBallLocation = controlBallTransform.origin; javax.vecmath.Vector3f cameraPosition = new javax.vecmath.Vector3f(camera.getPosition().x, camera.getPosition().y, camera.getPosition().z); javax.vecmath.Vector3f force = new javax.vecmath.Vector3f(); force.sub(cameraPosition, controlBallLocation); controlBall.activate(true); controlBall.applyCentralForce(force); } if (createNewShape) { createNewShape(0, 35, 0); } if (resetControlBall) { controlBall.setCenterOfMassTransform(DEFAULT_BALL_TRANSFORM); controlBall.setAngularVelocity(new javax.vecmath.Vector3f(0, 0, 0)); controlBall.setLinearVelocity(new javax.vecmath.Vector3f(0, 0, 0)); resetControlBall = false; } for(int i = 0; i < handler.objects.size(); i++) { GameObject object = handler.objects.get(i); if(object.getId() == ObjectID.PLAYER) { if(Keyboard.isKeyDown(Keyboard.KEY_UP)) object.getPosition().y += 0.04f; if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) object.getPosition().y -= 0.04f; if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) object.getPosition().x += 0.04f; if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) object.getPosition().x -= 0.04f; } } Display.sync(60); Display.update(); if (Mouse.isButtonDown(0) && !Mouse.isGrabbed()) { Mouse.setGrabbed(true); } else if (Mouse.isButtonDown(1) && Mouse.isGrabbed()) { Mouse.setGrabbed(false); } else if (Mouse.isButtonDown(0) && Mouse.isGrabbed()) { createNewShape(0, 35, 0); applyForce = true; } else { applyForce = false; } while (Keyboard.next()) { if (Keyboard.getEventKeyState()) { switch (Keyboard.getEventKey()) { case Keyboard.KEY_G: createNewShape = true; break; case Keyboard.KEY_F: resetControlBall = true; break; } } } } private void createNewShape(float x, float y, float z) { CollisionShape shape = new SphereShape(3.0f); DefaultMotionState motionState = new DefaultMotionState(new Transform(new javax.vecmath.Matrix4f(new Quat4f(0, 0, 0, 1), new javax.vecmath.Vector3f(x, y, z), 1))); javax.vecmath.Vector3f inertia = new javax.vecmath.Vector3f(); shape.calculateLocalInertia(1.0f, inertia); RigidBodyConstructionInfo constructionInfo = new RigidBodyConstructionInfo(1.0f, motionState, shape, inertia); constructionInfo.restitution = 0.75f; RigidBody body = new RigidBody(constructionInfo); dynamicsWorld.addRigidBody(body); balls.add(body); createNewShape = false; } private void input() { } private void destroy() { Display.destroy(); } public static void main(String[] args) { Game game = new Game(); game.init(); game.run(); } }
  11. I need a tutorial on how to implement Bullet Physics with Modern OpenGL, otherwise here is my problem: I am currently working on a game engine in LWJGL, legacy OpenGL fixed function pipeline. I am using Bullet Physics library for my physics engine and so far, everything is working excellent (cubes are colliding perfectly, spheres are colliding perfectly) but I don’t want to work in Legacy OpenGL, I want to work with modern OpenGL. The problem is that to make everything work perfectly in legacy OpenGL (my situation currently), I have to use glMultMatrix(). Now if I want to work with Modern OpenGL and have same results, I don’t know how. Because glMultMatrix() is deprecated, it can NOT be used in modern OpenGL. Source code (not all of it):
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!