Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Engines, Libraries and Tools / Slick libraries loading txt file on: 2012-06-08 05:37:47
In the slick libraries, are there any tools to load notepad files text?
2  Java Game APIs & Engines / OpenGL Development / Re: Font engine on: 2012-05-06 22:25:57
Is it bad to have too many textures? Does it clog RAM? But either way, im going to gradually delete the textures afterwards
3  Java Game APIs & Engines / OpenGL Development / Font engine on: 2012-05-04 03:07:34
I was wondering what would be a good way to make a Font engine with the LWJGL to write text. The one I wrote currently works like this:

1.) Create a new StaticText class object passing in the X Y positions and the string that will be displayed.

2.) In the StaticText constructor, create a blank texture, bind a FrameBufferObject for rendering, and render all the letters into that new texture

3.) Since the StaticText class is extended to Component which holds the x,y,textureId variables, the renderer can loop through the Component array and draw everything.

Basically, every text object is rendered in the beginning within its own textureID so it doesnt have to render each letter again after every frame. Is this a slow way of doing a font engine? Any feedback?




Thats a pic of my font engine. The red outline is the size of the texture. When you pass in different lines "/n" it calculates how big the width and height of the texture has to be to fit in all lines.
4  Java Game APIs & Engines / OpenGL Development / How to go from Texture Id to Texture object? on: 2012-04-29 05:09:56
When I use glGenTextures(). It only returns an int and not the texture itself. I want to keep track of all textures in an array but I have no way of storing it because well...it only returns an integer. How do I go about doing this? Do I even need to do this?
5  Java Game APIs & Engines / OpenGL Development / Re: Java LWJGL Cant use allocateDirect(int) undefined for type ByteBuffer on: 2012-04-26 23:32:40
*old answer deleted*

The question i really want to ask is how do you go from texture id number to Texture Object? Because when i use glGenTextures I have no way of saving the Texture Object since it only returns to me an integer.
6  Java Game APIs & Engines / OpenGL Development / Re: Java LWJGL Cant use allocateDirect(int) undefined for type ByteBuffer on: 2012-04-26 09:27:02
BufferUtils.createIntBuffer(int)?

Or even better:

glGenFramebuffer();

oh thats helpful. Also i noticed some of the functions in the wiki have EXT added to the end of its name. Why so?

also how do you use the glGenFrameBuffer() one.
7  Java Game APIs & Engines / OpenGL Development / Java LWJGL Cant use allocateDirect(int) undefined for type ByteBuffer on: 2012-04-26 07:32:55
http://www.lwjgl.org/wiki/index.php?title=Using_Frame_Buffer_Objects_(FBO)

I copied EXACTLY from the LWJGL wiki about Using Frame Buffer Objects the code:

1  
    IntBuffer buffer = ByteBuffer.allocateDirect(1*4).order(ByteOrder.nativeOrder()).asIntBuffer(); // allocate a 1 int byte buffer



The LWJGL is installed correctly but i get

    The method allocateDirect(int) is undefined for the type ByteBuffer

I dont know how to fix it. I updated my LWJGL lib and natives. Help
8  Java Game APIs & Engines / OpenGL Development / Re: Drawing On Textures on: 2012-04-10 07:09:15
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  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
package framework.base;

/**
 **   __ __|_  ___________________________________________________________________________  ___|__ __
 **  //    /\                                           _                                  /\    \\  
 ** //____/  \__     __ _____ _____ _____ _____ _____  | |     __ _____ _____ __        __/  \____\\
 **  \    \  / /  __|  |     |   __|  _  |     |  _  | | |  __|  |     |   __|  |      /\ \  /    /  
 **   \____\/_/  |  |  |  |  |  |  |     | | | |   __| | | |  |  |  |  |  |  |  |__   "  \_\/____/  
 **  /\    \     |_____|_____|_____|__|__|_|_|_|__|    | | |_____|_____|_____|_____|  _  /    /\    
 ** /  \____\                       http://jogamp.org  |_|                              /____/  \    
 ** \  /   "' _________________________________________________________________________ `"   \  /    
 **  \/____.                                                                             .____\/    
 **
 ** Utility wrapper class wich encapsulates the framebuffer-object feature (also known as render-
 ** 2-texture) of OpenGL in a more convenient way. Handles all the boilerplate initialization,
 ** runtime and cleanup code needed to use the FBO. The rendering calls must be provided as
 ** an implementation of the BaseFrameBufferObjectRendererInterface.
 **
 **/


import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.jogamp.common.nio.*;
import com.jogamp.opengl.util.gl2.*;
import static javax.media.opengl.GL2.*;

public class BaseFrameBufferObjectRendererExecutor {

    private int mFrameBufferObjectID;
    private int mColorTextureID;
    private int mDepthTextureID;
    private int mTextureWidth;
    private int mTextureHeight;
    private BaseFrameBufferObjectRendererInterface mBaseFrameBufferObjectRendererInterface;

    public BaseFrameBufferObjectRendererExecutor(int inTextureWidth,int inTextureHeight,BaseFrameBufferObjectRendererInterface inBaseFrameBufferObjectRendererInterface) {
        mTextureWidth = inTextureWidth;
        mTextureHeight = inTextureHeight;
        mBaseFrameBufferObjectRendererInterface = inBaseFrameBufferObjectRendererInterface;
    }

    public int getColorTextureID() { return mColorTextureID; }
    public int getDepthTextureID() { return mDepthTextureID; }
    public int getWidth() { return mTextureWidth; }
    public int getHeight() { return mTextureHeight; }

    public void init(GL2 inGL,GLU inGLU,GLUT inGLUT) {
        BaseLogging.getInstance().info("INITIALIZING BaseFrameBufferObjectRendererExecutor ... "+mTextureWidth+"x"+mTextureHeight);
        //allocate the framebuffer object ...
       int[] result = new int[1];
        inGL.glGenFramebuffers(1, result, 0);
        mFrameBufferObjectID = result[0];
        inGL.glBindFramebuffer(GL_FRAMEBUFFER, mFrameBufferObjectID);
        //allocate the colour texture ...
       inGL.glGenTextures(1, result, 0);
        mColorTextureID = result[0];
        inGL.glBindTexture(GL_TEXTURE_2D, mColorTextureID);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
        inGL.glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,mTextureWidth,mTextureHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,null);
        //allocate the depth texture ...
       inGL.glGenTextures(1, result, 0);
        mDepthTextureID = result[0];
        inGL.glBindTexture(GL_TEXTURE_2D, mDepthTextureID);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
        inGL.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
        inGL.glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT32,mTextureWidth,mTextureHeight,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_INT,null);
        //attach the textures to the framebuffer
       inGL.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,mColorTextureID,0);
        inGL.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,mDepthTextureID,0);
        inGL.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        //check if fbo is set up correctly ...
       checkFrameBufferObjectCompleteness(inGL);
        if (mBaseFrameBufferObjectRendererInterface!=null) {
            //initialize the assigned fbo renderer ...
           mBaseFrameBufferObjectRendererInterface.init_FBORenderer(inGL,inGLU,inGLUT);
        } else {
            BaseLogging.getInstance().warning("BaseFrameBufferObjectRendererInterface FOR THIS EXECUTOR IS NULL! init_FBORenderer() SKIPPED!");
        }
    }

    public void renderToFrameBuffer(int inFrameNumber,GL2 inGL,GLU inGLU,GLUT inGLUT) {
        inGL.glPushAttrib(GL_TRANSFORM_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
            //bind the framebuffer ...
           inGL.glBindFramebuffer(GL_FRAMEBUFFER, mFrameBufferObjectID);
            inGL.glPushAttrib(GL_VIEWPORT_BIT);
            inGL.glViewport(0,0,mTextureWidth,mTextureHeight);
            if (mBaseFrameBufferObjectRendererInterface!=null) {
                mBaseFrameBufferObjectRendererInterface.mainLoop_FBORenderer(inFrameNumber,inGL,inGLU,inGLUT);
            } else {
                BaseLogging.getInstance().warning("BaseFrameBufferObjectRendererInterface FOR THIS EXECUTOR IS NULL! renderToFrameBuffer() SKIPPED!");
            }
            inGL.glPopAttrib();
            //unbind the framebuffer ...
           inGL.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        inGL.glPopAttrib();
    }

    public void prepareForColouredRendering(GL2 inGL, int inTextureUnitID) {
        inGL.glPushAttrib(GL_TEXTURE_BIT);
        inGL.glActiveTexture(inTextureUnitID);
        inGL.glBindTexture(GL_TEXTURE_2D, mColorTextureID);
        //set the texture up to be used for painting a surface ...
       int textureTarget = GL_TEXTURE_2D;
        inGL.glEnable(textureTarget);
        inGL.glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
        inGL.glTexParameteri(textureTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        inGL.glTexParameteri(textureTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        inGL.glTexParameteri(textureTarget,GL_TEXTURE_WRAP_S,GL_REPEAT);
        inGL.glTexParameteri(textureTarget,GL_TEXTURE_WRAP_T,GL_REPEAT);
    }

    public void stopColouredRendering(GL2 inGL) {
        inGL.glBindTexture(GL_TEXTURE_2D, 0);
        //restore the active texture ...
       inGL.glPopAttrib();
    }
   
    public void renderFBOAsFullscreenBillboard(GL2 inGL,GLU inGLU,GLUT inGLUT) {
        renderFBOAsFullscreenBillboard(inGL,inGLU,inGLUT,false);
    }

    public void renderFBOAsFullscreenBillboard_FLIPPED(GL2 inGL,GLU inGLU,GLUT inGLUT) {
        renderFBOAsFullscreenBillboard(inGL,inGLU,inGLUT,true);
    }

    public void renderFBOAsFullscreenBillboard(GL2 inGL,GLU inGLU,GLUT inGLUT,boolean inFlipped) {
        //reset frustum to default state ...
       BaseRoutineRuntime.resetFrustumToDefaultState(inGL,inGLU,inGLUT);
        inGL.glShadeModel(GL_SMOOTH);
        inGL.glDisable(GL_LIGHTING);
        inGL.glFrontFace(GL_CCW);
        inGL.glDisable(GL_CULL_FACE);
        //disable depth test so that billboards can be rendered on top of each other ...
       inGL.glDisable(GL_DEPTH_TEST);        
        inGL.glMatrixMode(GL_PROJECTION);
        inGL.glLoadIdentity();
        inGL.glOrtho(0, BaseGlobalEnvironment.getInstance().getScreenWidth(), BaseGlobalEnvironment.getInstance().getScreenHeight(), 0, -1, 1);
        inGL.glMatrixMode(GL_MODELVIEW);
        inGL.glLoadIdentity();
        this.prepareForColouredRendering(inGL,GL_TEXTURE0);
        inGL.glBegin(GL_QUADS);
        if (inFlipped) {
            //flipped billboard
           inGL.glTexCoord2f(0.0f, 0.0f);
            inGL.glVertex2f(0.0f, 0.0f);
            inGL.glTexCoord2f(1.0f, 0.0f);
            inGL.glVertex2f(BaseGlobalEnvironment.getInstance().getScreenWidth(), 0.0f);
            inGL.glTexCoord2f(1.0f, 1.0f);
            inGL.glVertex2f(BaseGlobalEnvironment.getInstance().getScreenWidth(), BaseGlobalEnvironment.getInstance().getScreenHeight());
            inGL.glTexCoord2f(0.0f, 1.0f);
            inGL.glVertex2f(0.0f, BaseGlobalEnvironment.getInstance().getScreenHeight());
        } else {
            inGL.glTexCoord2f(0.0f, 1.0f);
            inGL.glVertex2f(0.0f, 0.0f);
            inGL.glTexCoord2f(1.0f, 1.0f);
            inGL.glVertex2f(BaseGlobalEnvironment.getInstance().getScreenWidth(), 0.0f);
            inGL.glTexCoord2f(1.0f, 0.0f);
            inGL.glVertex2f(BaseGlobalEnvironment.getInstance().getScreenWidth(), BaseGlobalEnvironment.getInstance().getScreenHeight());
            inGL.glTexCoord2f(0.0f, 0.0f);
            inGL.glVertex2f(0.0f, BaseGlobalEnvironment.getInstance().getScreenHeight());    
        }
        inGL.glEnd();
        this.stopColouredRendering(inGL);
    }

    public void cleanup(GL2 inGL,GLU inGLU,GLUT inGLUT) {
        inGL.glDeleteFramebuffers(1, Buffers.newDirectIntBuffer(mFrameBufferObjectID));
        inGL.glDeleteTextures(1, Buffers.newDirectIntBuffer(mColorTextureID));
        inGL.glDeleteTextures(1, Buffers.newDirectIntBuffer(mDepthTextureID));
        if (mBaseFrameBufferObjectRendererInterface!=null) {
            mBaseFrameBufferObjectRendererInterface.cleanup_FBORenderer(inGL,inGLU,inGLUT);
        } else {
            BaseLogging.getInstance().warning("BaseFrameBufferObjectRendererInterface FOR THIS EXECUTOR IS NULL! cleanup() SKIPPED!");
        }
    }

    private void checkFrameBufferObjectCompleteness(GL2 inGL) {
        BaseLogging.getInstance().info("CHECKING FRAMEBUFFEROBJECT COMPLETENESS ...");
        int tError = inGL.glCheckFramebufferStatus(GL_FRAMEBUFFER);
        switch(tError) {
            case GL_FRAMEBUFFER_COMPLETE:
                BaseLogging.getInstance().info("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_COMPLETE_EXT");
                break;
            case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
                BaseLogging.getInstance().error("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT");
                break;
            case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
                BaseLogging.getInstance().error("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
                break;
            case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
                BaseLogging.getInstance().error("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT");
                break;
            case GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
                BaseLogging.getInstance().error("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");
                break;
            case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
                BaseLogging.getInstance().error("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
                break;
            case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
                BaseLogging.getInstance().error("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
                break;
            case GL_FRAMEBUFFER_UNSUPPORTED:
                BaseLogging.getInstance().error("FRAMEBUFFEROBJECT CHECK RESULT=GL_FRAMEBUFFER_UNSUPPORTED_EXT");
                break;
            default:
                BaseLogging.getInstance().error("FRAMEBUFFER CHECK RETURNED UNKNOWN RESULT ...");
        }
    }

}
9  Java Game APIs & Engines / OpenGL Development / Re: Drawing On Textures on: 2012-04-09 05:41:59
There are numerous ways to modify textures, but generally FBO or shaders are accepted as the best practices for this kind of thing.

FBOs will probably be easier to begin with. In brief:
- create a new texture for your FBO
- bind your FBO to "begin drawing offscreen"
- draw operations will now affect the FBO texture
- unbind your FBO, returning the rendering to normal
- render your now-modified FBO texture to the screen

Here's a JOGL example:
https://github.com/demoscenepassivist/SocialCoding/blob/master/code_demos_jogamp/src/framework/base/BaseFrameBufferObjectRendererExecutor.java

If you're targeting very old systems, you might need to look into PBuffers as a fallback.
Yes thank you very much thats what I needed. I understand bits of it but I have one question regarding that code. Does the init() function fire first? Or do you need to throw in arguments to some function for it to start. If so, what function, I can't seem to find it.
10  Java Game APIs & Engines / OpenGL Development / Re: Particle System question on: 2012-03-20 01:42:18
K i understand it now. However, when I bind a texture to use for VBO, I use a large sprite sheet. Obviously I dont want to render the entire sheet so how do i bind a specific texture coordinate of a large image?
11  Java Game APIs & Engines / OpenGL Development / Drawing On Textures on: 2012-03-08 00:25:49
In normal Java, id have a bufferedImage to draw on, have fun with it, and then paste it on the screen. How do i go about to do about the same in JOGL?
12  Java Game APIs & Engines / OpenGL Development / Re: Cropping out images for usage. on: 2012-03-04 21:42:08
So how does this translate into drawing on textures?
13  Java Game APIs & Engines / OpenGL Development / Re: Cropping out images for usage. on: 2012-03-03 07:47:09
Also i have another question regarding images and textures. In normal Java, i usually create a BufferedImage in which I can draw on background images, items, props, whatever, and then draw that bufferedimage on the screen. I want to do the same on JOGL. How do i make a texture in which i can draw on?
14  Java Game APIs & Engines / OpenGL Development / Re: Particle System question on: 2012-02-28 03:44:18
I just got my particles system working using vertex arrays and the performance boost was insane. Almost double the particle count. It is 2D and I could send you the code or you can google opengl vertex arrays/VBO if your using lwjgl then

http://lwjgl.org/wiki/index.php?title=Using_Vertex_Buffer_Objects_%28VBO%29

hope this helps.

I didnt understand it very well...  Clueless . Ill research more sources...
15  Java Game APIs & Engines / OpenGL Development / Re: Cropping out images for usage. on: 2012-02-28 00:33:28
I never thought about that. How can i resolve it? Now it wont be a problem since i wont be creating/deleting textures, but later it might...
16  Java Game APIs & Engines / OpenGL Development / Re: Particle System question on: 2012-02-28 00:26:03
Oh, god... You're doing 10 OpenGL calls for each particle... Kill it with fire! Store the data in a ByteBuffer and upload it to a VBO each frame, and draw everything with glDrawArrays.

If you're still having a problem with the texture drifting then I suspect the problem is your texture coordinates. If you can't figure it out, post the code for the methods that generate the texture coordinates.

Yeah thats my next task for optimizing this code. But i dont know how to use VBO arrays. Im still looking for a tutorial specifically for 2D only...
17  Java Game APIs & Engines / OpenGL Development / Re: Cropping out images for usage. on: 2012-02-28 00:23:54

There is an array with the CropInfo so if you wanna get the crop subimage info for say texture # 5, you go to the array and retrieve the 4th index because JOGL starts the first texture ID with number 1. In other words, arrays are 0,1,2,3,4...... But the JOGL texture ID itself goes 1,2,3,4,5. So thats why i subtracted one from the texture ID, so i can call it from an array neatly.
18  Java Game APIs & Engines / OpenGL Development / Re: Particle System question on: 2012-02-27 08:59:42
You're going a bit crazy with premature optimization here. In a particle system your bottleneck is much more likely to lie in fill rate / GPU. A few extra divisions (or primitive type casts for that matter) are negligible, i.e. including them won't affect your particle system's performance in any detectable way.

A more sane optimization would be to only call glBegin/glEnd once per loop; then repeat the drawing code (glTexCoord/glVertex) as necessary for each particle.

Better still would be to use vertex arrays:
http://www.songho.ca/opengl/gl_vertexarray.html

Oh great. K thanks. By the way, do you know any tutorials for vertex array buffers for 2D?
19  Java Game APIs & Engines / OpenGL Development / Re: Particle System question on: 2012-02-27 07:46:42
I managed to remove 6 of the divisions by precalculating the width and height offsets. Still i hate using divisions in loops. Heres the code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
int hw = p.getWidth()/2;
int hh = p.getHeight()/2;
glBegin(GL_QUADS);
   glTexCoord2f(ci.getXD(),ci.getYD());// Upper-left
  glVertex2i((int)p.getX()-hw, (int)p.getY()-hh);
   glTexCoord2f(ci.getXWD(), ci.getYD());// Upper-right
  glVertex2i((int)p.getX()+hw, (int)p.getY()-hh);
   glTexCoord2f(ci.getXWD(), ci.getYHD());// Bottom-right
  glVertex2i((int)p.getX()+hw, (int)p.getY()+hh);
   glTexCoord2f(ci.getXD(), ci.getYHD()); // Bottom-left
  glVertex2i((int)p.getX()-hw, (int)p.getY()+hh);
glEnd();
20  Java Game APIs & Engines / OpenGL Development / Particle System question on: 2012-02-27 07:01:22
I have a particle system and one of the behaviors is Smoke. So each particle starts small and grows big until it fades away. A problem with this is the fact that since the texture is being enlarged, it appears as if it is moving to the right. This can be resolved by rendering the particle┬┤s x position minus half its width. However, this small division when coupled with thousands of particles can cause performance drops. My question is, is there another way to remove the "drifting to the right" bug? Perhaps an optimization? My code with the division is...


P.S. The bug also affects the image to look like its drifting down. Thus the minus half the height in the code:


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
glBegin(GL_QUADS);
   glTexCoord2f(ci.getXD(),ci.getYD());// Upper-left
  glVertex2i((int)p.getX()-p.getWidth()/2, (int)p.getY()-p.getHeight()/2);
   glTexCoord2f(ci.getXWD(), ci.getYD());// Upper-right
  glVertex2i((int)p.getX()+p.getWidth()/2, (int)p.getY()-p.getHeight()/2);
   glTexCoord2f(ci.getXWD(), ci.getYHD());// Bottom-right
  glVertex2i((int)p.getX()+p.getWidth()/2, (int)p.getY()+p.getHeight()/2);
   glTexCoord2f(ci.getXD(), ci.getYHD()); // Bottom-left
  glVertex2i((int)p.getX()-p.getWidth()/2, (int)p.getY()+p.getHeight()/2);
glEnd();
21  Java Game APIs & Engines / OpenGL Development / Re: Cropping out images for usage. on: 2012-02-27 05:13:35
oh okay cool. What is it? Lol in the meantime, i devised my own tool for automatic coordinate generator:

Oh here i finished it:

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  
import org.newdawn.slick.opengl.Texture;


public class CropInfo {
   
   private float xd,yd,xwd,yhd;
   private int textureId;
   
   public CropInfo(Texture texture, int X, int Y, int W, int H){
      textureId = texture.getTextureID()-1;
      float texWidth = texture.getImageWidth();
      float texHeight = texture.getImageHeight();
      xd = X/texWidth;
      yd = Y/ texWidth;
      xwd = (X+W)/texWidth;
      yhd = (Y+H)/texHeight;
   }
   public int getTextureId() {
      return textureId;
   }
   public float getXD(){
      return xd;
   }
   public float getYD(){
      return yd;
   }
   public float getXWD(){
      return xwd;
   }
   public float getYHD(){
      return yhd;
   }
}


yeah and then all you need to do for the drawing is just

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
CropInfo ci = im.getCropInfo(blah blah....

glBegin(GL_QUADS);
   glTexCoord2f(ci.getXD(),ci.getYD());// Upper-left
  glVertex2i(100, 100);
   glTexCoord2f(ci.getXWD(), ci.getYD());// Upper-right
  glVertex2i(500, 100);
   glTexCoord2f(ci.getXWD(), ci.getYHD());// Bottom-right
  glVertex2i(500, 500);
   glTexCoord2f(ci.getXD(), ci.getYHD()); // Bottom-left
  glVertex2i(100, 500);
22  Java Game APIs & Engines / OpenGL Development / Re: Cropping out images for usage. on: 2012-02-27 05:01:11
Oh okay. Also, im using the glTexCoord2f to texturize different sections of the big sprite sheet. However, its really annoying manually specifying the top left, top right, blah blah coordinates for EVERY single type of little sprite image. Is there a better more humane way to do this?
23  Java Game APIs & Engines / OpenGL Development / Re: Cropping out images for usage. on: 2012-02-25 00:08:49
No thats ineffecient and slow because the sprite sheet is usually very big. I still need help Sad
24  Java Game APIs & Engines / OpenGL Development / Cropping out images for usage. on: 2012-02-24 20:55:45
So i am recently transitioning to JOGL, and Im wandering how one goes about to crop/cut out textures out of a sheet of sprites to use for texture binding and everything else.... I cant find any tutorials  persecutioncomplex. Can anybody provide with a link or code?
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (11 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (108 views)
2014-04-08 23:06:04

tom_mai78101 (208 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!