[SOLVED] Only one pixel of texture when trying to draw textured quad !

Started by Yuri6037, May 20, 2013, 12:19:25

Previous topic - Next topic

Yuri6037

I'm trying to draw a textured quad with LWJGL, but I don't know why my quad renders with only one pixel of color.

This is the first time that i use LWJGL to create a 2D Fullscreen game.

Here's the code used to draw the quad:

--PRIVATE--
Here's the code for load texture image:

--PRIVATE--
Here's the code for binding textures:

--PRIVATE--
Here's init game code:

--PRIVATE--
I have tried many things for rendering textured quads for this game. This is a "break the brick" game who can play with DataInputStream used for multiplayer.

In the paste I have created this game using JAVA2D and javax.swing, but due to lags and compatibility problems on Windows Non Areo Systems (XP, ...) and with some Linux and Mac I've decided to reconstruct the rendering code with LWJGL.

Can you help me?

Fool Running

You need to specify what point of the texture corresponds to each vertex (where 0 represents the left or top and 1 represents the right or bottom).
Try something like:
    glBegin(GL_QUADS);
    {
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(x, y);
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex2f(width + x, y);
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex2f(width + x, height + y);
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex2f(x, height + y);
    }

You might have to flip the Y-values because of the way OpenGL's coordinates work (i.e. (0,0) is normally bottom-left instead of top-left).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Yuri6037

Thanks this ok but the textures are completely strange !
I know why because textures sizes are not a puissance of 2 !
So the new question is How can i render textures with sizes diffrent of a puissance of 2 ?
Puissance of 2 textures sizes example :
16 x 16
32 x 32
64 x 64
...

quew8

Create a texture the next power of two size up. Use glTexSubImage to put your image in the 0 - image size range. Then for tex coords instead of 1, use ( yourTextureSize / wholeTextureSize );

Example:

You have an image 82 x 82. Create a texture 128 x 128. Put your texture in at 0, 0. Use texture coordinates
(0, 0) (0, 82/128) (82/128,  82/128) (82/128, 0)

Yuri6037

I'm so sorry i can't resize my images that's the RenderEngine who needs to be adapted to my images !
So can you help me found a way to render correctly !
In plus i can't make any timer in LWJGL !
When i try to init my timer i get an error :
Exception in thread "timer tick thread" : No opengl context found in current thread !
So i think i will search another library because crash when using multi thread !

quew8

That crash is an OpenGL thing. The context can only be current on one thread at a time. You will find any OpenGL library has the same thing. If you want a timer, see the wiki page on timing: http://www.lwjgl.org/wiki/index.php?title=LWJGL_Basics_4_(Timing). And my solution to you non-pot images was a way to change the rendering engine.

Yuri6037

Thanks for timers examples i'm making an idea !
In revenge don't know how to draw my images correctly !
And after all of that I'm getting a new problem :
When i use loop in my render and update voids i'm getting a long freeze and after Java has stopped working windows is searching a solution to the problem ! And IntelliJ is telling me that the application has exited !
Can you help me !

quew8


Yuri6037

Here is Window.java code (the GUI system) :
--PRIVATE--

You will see the ConcurrentModifyException ! I don't know how to get rif of these errors !

quew8

Probably thrown because you are trying to edit the contents of windowComponents whilst iterating over it. So you are accessing the collection in updateComponent() or in renderComponent() and you can't.

You are using slick right? Shouldn't you be extending the GameContainer class for your window. You seem to use the methods from GameContainer but not to actually extend or have an instance of it. Your code on the whole is very hard to make sense of.

(Also there is a code button in the post gui (it looks like a hash) which you can use to make code snippets clearer, example:
public class Foo {
    public static void main(String[] args) {
        //Some random code.
    }
}

)

Yuri6037

I'm not using slick !
I use only it for render class search as Graphics, Image, Font, ...

For understand better my code you need my Client class (main game class), you will see that i don't use Slick because Slick make my computer very laggy.

Here's the Client class :
--PRIVATE--

Please, can you do anything, please !
I'm completly dissapointed by the Java has stopped working error !
I know that my code is extremly long and not clean ! In effect my game is currently not published and i can't remove all unused codes, because of the error (Java has stopped working) !



Yuri6037

So super i have founded why Java has stopped working, it seams to be the ConcurrentModificationException throwed when i change window from MainMenu to GameWindow !

Now the question is how can i debug the ConcurrentModificationException !

quew8

Ok, first off - why does BrickBroken implement Runnable? You start it as a thread in main() but your run() method is empty. You shouldn't be working with threads anyway - games use them only very rarely. If you need something to be done, it has to be called from your main game loop.

You have a lot of complex stuff in your code that I think it would be better for you to just leave for now. You have, for instance, what I think is meant to be a loading cycle where you display an image on the screen for a set time. For now get rid of it. (comment out anything to do with it). Same goes for your gui stuff. (That is what is causing the error and I need to see the GameComponent / ComponentAction and the stack trace of the exception to be more specific). At the moment your code is a mess and I think this is stopping you from seeing the errors in your code. For example you have a lot of commented out code that I presume is legacy code and yet you haven't got rid of it. Personally, with a code base like that I would just start over but that's your choice.

I said before about the code button. It really does make everything clearer.

quew8

Like above, I need to see the GameComponent class and stack trace.

Yuri6037

Ok So Thanks !
I have resolved my problem of Java has stopped working, now i can play my game until i change window because the Java.util.ConcurentModificationException is always here !

Info : The game update and render are now called by Slick2D !

So here is the stack trace :
--PRIVATE--

Window.java code :
--PRIVATE--

GameComponent.java code :
--PRIVATE--

Code used to display windows :
--PRIVATE--

I hope you can now tell me how to fix ConcurrentModificationException !