Show Posts
|
|
Pages: [1] 2
|
|
2
|
Game Development / Newbie & Debugging Questions / Re: Not able to render my font :(
|
on: 2013-05-12 16:18:35
|
Well for starters, you have different letters placed on different rows and columns so setting the column to always be one seems a bit dodgy to me. The way i would approach this is something like this: (this is from my entry to last Decembers Ludum Dare so it is not all exactly the same as yours) 1 2 3 4 5 6 7 8 9 10 11 12 13
| public class Font { private static String alph0 = "abcdefghijklmnopqrstuvwxyz0123456789.,:;'\"!?$%()-=+/ "; public static void renderText(String t, Bitmap b, int xp, int yp) { t = t.toLowerCase(); for(int x = 0; x < t.length(); x++) { int drawIndex = alph0.indexOf(t.charAt(x)); if (drawIndex != 52) { b.blit(Image.font[drawIndex % 26][drawIndex / 26], x * 16 + xp, yp, 1.0f, false, false); } } } } |
The first deimension of the Image.font array represents the column while the second dimension represents the row. I hope this helps 
|
|
|
|
|
3
|
Game Development / Newbie & Debugging Questions / Is this the best way to work VBOs?
|
on: 2013-05-12 16:11:53
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| public class RenderEngine { private FloatBuffer fb; int vch = 1;
public RenderEngine() { fb = BufferUtils.createFloatBuffer(100 * 10 * 10 * 6 * 4 * 6);
fb.flip(); } public void render() { if(!bFlipped) { fb.flip(); bFlipped = true; }
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vch); glBufferDataARB(GL_ARRAY_BUFFER_ARB, fb, GL_STATIC_DRAW_ARB); glVertexPointer(3, GL_FLOAT, (3 * 2) << 2, 0); glColorPointer(3, GL_FLOAT, (3 * 2) * 4, 3 * 4);
glDrawArrays(GL_QUADS, 0, fb.capacity() / 4);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); } } |
This code seems somewhat inefficient to me for a number of reasons: - The vch variable is defaulted to 1 and I'm not really 100% sure why this works, I imagine this is used for rendering multiple VBOs
- Every time I go to render the VBO, i redo the glBufferData() call, I have seen examples where people call this once when they initialise the VBO and not every render cycle
If anyone could give me any pointers on mistakes I have made please let me know. (please note, this code does work, I just don't see it as very efficient which is why I'm asking)
|
|
|
|
|
5
|
Game Development / Newbie & Debugging Questions / Re: OpenGL Texutre animating
|
on: 2013-02-20 19:31:09
|
They are simply re-uploading the modified texture part into the terrain-texture-atlas on the graphicscard. And because of performance reasons this happens only if the texture is really modified. The textures are stored in a way, so they can be directly uploaded to the graphicscard.
The whole thing is very (very) easy to implement if you know how to upload a texture to opengl.
- Longor1996
OK, so how does one go about uploading a texture to OpenGL I understand you can regenerate the texture and add the glTexImage2d(); function with the pixels array, or is this something different?
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / Re: OpenGL Texutre animating
|
on: 2013-02-20 14:17:42
|
Here's the decompiled Minecraft water class from MCP. In here you can see them changing the individual pixel values. How would they go about applying those pixels to an object? It is decompiled so it could be hard to read, but im just trying to show you how they implement pixel changing 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| package net.minecraft.src;
public class TextureWaterFX extends TextureFX { protected float[] red = new float[256];
protected float[] green = new float[256];
protected float[] blue = new float[256];
protected float[] alpha = new float[256]; private int tickCounter = 0;
public TextureWaterFX() { super(Block.waterMoving.blockIndexInTexture); }
public void onTick() { ++this.tickCounter; int var1; int var2; float var3; int var5; int var6;
for (var1 = 0; var1 < 16; ++var1) { for (var2 = 0; var2 < 16; ++var2) { var3 = 0.0F;
for (int var4 = var1 - 1; var4 <= var1 + 1; ++var4) { var5 = var4 & 15; var6 = var2 & 15; var3 += this.red[var5 + var6 * 16]; }
this.green[var1 + var2 * 16] = var3 / 3.3F + this.blue[var1 + var2 * 16] * 0.8F; } }
for (var1 = 0; var1 < 16; ++var1) { for (var2 = 0; var2 < 16; ++var2) { this.blue[var1 + var2 * 16] += this.alpha[var1 + var2 * 16] * 0.05F;
if (this.blue[var1 + var2 * 16] < 0.0F) { this.blue[var1 + var2 * 16] = 0.0F; }
this.alpha[var1 + var2 * 16] -= 0.1F;
if (Math.random() < 0.05D) { this.alpha[var1 + var2 * 16] = 0.5F; } } }
float[] var12 = this.green; this.green = this.red; this.red = var12;
for (var2 = 0; var2 < 256; ++var2) { var3 = this.red[var2];
if (var3 > 1.0F) { var3 = 1.0F; }
if (var3 < 0.0F) { var3 = 0.0F; }
float var13 = var3 * var3; var5 = (int)(32.0F + var13 * 32.0F); var6 = (int)(50.0F + var13 * 64.0F); int var7 = 255; int var8 = (int)(146.0F + var13 * 50.0F);
if (this.anaglyphEnabled) { int var9 = (var5 * 30 + var6 * 59 + var7 * 11) / 100; int var10 = (var5 * 30 + var6 * 70) / 100; int var11 = (var5 * 30 + var7 * 70) / 100; var5 = var9; var6 = var10; var7 = var11; }
this.imageData[var2 * 4 + 0] = (byte)var5; this.imageData[var2 * 4 + 1] = (byte)var6; this.imageData[var2 * 4 + 2] = (byte)var7; this.imageData[var2 * 4 + 3] = (byte)var8; } } } |
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / [ANSWERED] OpenGL Texutre animating
|
on: 2013-02-20 13:21:41
|
|
In Opengl, how would you go about modifying the colour value of each pixel on a texture? Take, for example, in Minecraft, where the water pulses changing colour. Im not interested in the alogirthm behind changing the colour data for the pixels, I'm more inerested in how you would go about applying the moddified texture to an object.
I realise you could probably regenerate the texture each frame but that seems slow and inefficient. Is there a better way to do it?
|
|
|
|
|
10
|
Game Development / Newbie & Debugging Questions / Tile Map Connected Textures
|
on: 2013-02-18 19:50:02
|
|
What's the best way way to achieve smooth texture transitions between tiles in a tile mapped game, and not have the hard edge tiles normally produce.
I saw notch in minicraft had used his coloring technique to join the tiles together, but im using tiles that are statically coloured in the image editor
|
|
|
|
|
12
|
Game Development / Newbie & Debugging Questions / Re: Vector Drawing?
|
on: 2013-01-28 18:17:56
|
For starters i should point out that a normal vector actually represents a direction not a point (however looking over your code i don't think you meant what I'm on about here). Secondly, I cannot see any thing wrong with the implementation of the drawing except i think the issue is where you position the vector 1
| Vec2 normal = new Vec2(posX, posY); |
This piece of code is outside the constructor when it should really be inside it like this 1 2 3 4 5 6
| public Avatar (int x, int y, int w, int h, int s, int hp, int str){ super(w/2, h/2, w, h, s); hitPoints = hp; strength = str; normal = new Vec2(posX, posY); } |
|
|
|
|
|
13
|
Game Development / Newbie & Debugging Questions / Re: LWJGL Keyboard, what's going on?
|
on: 2013-01-28 17:48:27
|
It's todo with the way how when you call Mouse.next() or Keyboard.next() it polls the event so it cannot be used again that tick. The way i Would solve that particular issue is to create a seperate input class like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public class InputHandler { public boolean keysStream[] = new boolean[65536]; public void tickInput(){ while(Keyboard.next()){ if(Keyboard.getEventKeyState()){ keysStream[Keyboard.getEventKey()]=true; }else{ keysStream[Keyboard.getEventKey()]=false; } } while(Mouse.next()){ }
} } |
|
|
|
|
|
17
|
Game Development / Newbie & Debugging Questions / Re: Ok Lets Get Started --- Where to Begin
|
on: 2012-12-25 10:09:15
|
|
The best thing to do is to just make sure you actually just do something. If you sit around watching tutorials and not understanding, or thinking up games in your head you get nowhere. I found that if you just go out and do something, even if your not certain of how you'll do certain things, give it a go and eventually you'll build up your knowledge base and you'll learn about your own style of coding.
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / [SOLVED] Java issue with referencing
|
on: 2012-12-25 09:50:10
|
So i'm trying to draw the pixels of a Bitmap to the screen with a modified colour. What i want, is for the image to be drawn with an offset colour but to not change the actual pixels stored for that image. Currently im having issues with this. Here's my method 1 2 3 4 5 6 7 8 9 10 11 12 13
| public void renderWithColourOffset(Bitmap b,int xp,int yp,boolean xFlip,boolean yFlip,int col1[],int col2[]){ Bitmap b0 = new Bitmap(b); for(int i=0;i<b0.pixels.length;i++){ for(int c=0;c<col1.length;c++){ if(b0.pixels[i]==col1[c]){ b0.pixels[i] = col2[c]; } } } render(b0,xp,yp,xFlip,yFlip); } |
The issue is that when it does this it changes to pixels in the original Bitmap parsed to the function so it wont work whenever the function is called again. This seems to be an issue with java referencing but i've tried a lot of things and simply can't get it to work :S Oh and by the way, Merry Christmas 
|
|
|
|
|
21
|
Game Development / Newbie & Debugging Questions / Re: WHY DOES THIS WORK o.0
|
on: 2012-12-17 20:52:03
|
|
Let me rephrase it slightly, I want to know at what point in the program does the program know to render that pixel array to the screen, because if i rename it, it still works.
In the render function the pixel array is never called apart from to edit it, so how does the program know to use it?
|
|
|
|
|
22
|
Game Development / Newbie & Debugging Questions / [SOLVED]WHY DOES THIS WORK o.0
|
on: 2012-12-17 20:41:57
|
So I've been making 2D java games with the same setup for a long time but i don't understand how it works Here's the code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| package com.dazkins.alone;
import java.awt.Canvas; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.util.Random;
import javax.swing.JFrame;
public class AloneComponent extends Canvas implements Runnable{
private static final int WIDTH = 256; private static final int HEIGHT = 256; private static final int SCALE = 3; private boolean running = false; private BufferedImage img = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB); private int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData(); public static void main(String args[]){ AloneComponent c = new AloneComponent(); JFrame frame = new JFrame("Alone"); frame.add(c); frame.setVisible(true); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); c.start(); } public AloneComponent(){ Dimension d = new Dimension(WIDTH*SCALE,HEIGHT*SCALE); setPreferredSize(d); setMaximumSize(d); setMinimumSize(d); } public void start(){ running = true; Thread t = new Thread(this); t.start(); } public void stop(){ running = false; } public void tick(){ } public void render(){ BufferStrategy bs = getBufferStrategy(); if(bs==null){ createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); for(int i=0;i<pixels.length;i++){ pixels[i] = new Random().nextInt(0x0000FF) << 16; } g.drawImage(img, 0, 0, getWidth(), getHeight(), null); g.dispose(); bs.show(); } public void run() { while(running){ tick(); render(); } } } |
My question is about that the array of pixels that is used to store colour data for each pixel. I understand how it represents colours, but i don't understand atall at what part in the code that pixel array is asigned to the BufferedImage or rendered to the screen
|
|
|
|
|
23
|
Java Game APIs & Engines / OpenGL Development / Re: Pyramid, Cube in LWJGL
|
on: 2012-12-04 08:55:34
|
|
You pretty much have to put all the vertexes for a 3D object together yourself. Eventually you will get used to drawing the basic shapes such as cubes and triangles
Another way you can do this is set up some kind of static render function in a class the takes positional and size parameters and then easily draws one of those shapes to the screen. This means you don't have to repeat the algorithm every time you want to do it. So say for example if you wanted to draw a blocky man, like minecraft steve, you would just be able to add a bunch of cubes to his model data rather than having to enter in each of his vertexes
|
|
|
|
|
25
|
Game Development / Newbie & Debugging Questions / [SOLVED]Rotation around a point
|
on: 2012-12-03 14:05:53
|
So i'm writing out a program to lock a camera to an entity or object in my game The rotation works fine and seems to rotate correctly but the center about which it rotates is off. I reckon i understand why it's not working i just don't know how to fix it Here's the code 1 2 3 4 5 6
| public void lockCameraToEntity(Entity e,float x,float y,float z){ float hyp = (float)Math.sqrt(x*x+z*z); this.pos.x=(float)(-(e.pos.x+x) + (Math.sin(Math.toRadians(e.rot.y))*hyp)+hyp); this.pos.y=-(e.pos.y+y); this.pos.z=(float)(-(e.pos.z+z) + (Math.cos(Math.toRadians(e.rot.y))*hyp)+hyp); } |
|
|
|
|
|
27
|
Game Development / Newbie & Debugging Questions / Re: Implementation of 3D perlin noise
|
on: 2012-10-29 13:41:36
|
|
Just a quick note for anyone looking at this post. I realized my mistake
Instead of parsing x,y,z into the noise function, the x,y and z coords were to big and were giving too much variation I solved this by dividing the coords by the dimensions of the map
e.g
the map is 50x50x50 blocks and the blocks im parsing's coords are 35,46,12
what i should parse into the noise function is 35/50,46/50,12/50
You can divide it by different numbers to achieve different levels of variation
|
|
|
|
|
29
|
Game Development / Newbie & Debugging Questions / Why all the file based games?
|
on: 2012-10-27 15:05:19
|
When i'm looking for little tips and tricks on making games in Java people always seem to suggest to me making databases and using files to load in data for the game WHY  Personally I've found writing things out in code is better because you can individually script certain items if you wanted and you can have lots of customization but when you use a database or load things in from a file you have less customization options. I can understand certain things like a tile map should be done in a file but why things like item data, why cant that be done in code 
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Implementation of 3D perlin noise
|
on: 2012-10-24 08:45:34
|
I'va got a basic 3D perline noise algorithm and i'm trying to use it to generate terrain. After looking across the internet, most people seemed to tell me to use it as a volume system so if the noise value at that point is bigger than 0 place a block there. My current code looks likes this 1
| ClassicNoise.noise(x, y, z) > 0 |
I still only get a bunch of random blocks though :S, waht have i done wrong 
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|