Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LWJGL] Basic texture velocity  (Read 1251 times)
0 Members and 1 Guest are viewing this topic.
Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Posted 2014-05-04 22:14:57 »

Basically all I did was load a texture using the Slick_util and need to move it. Based on my game dev experience, would I just make a getter and setter for the velocity and x and y coordinates? I read on this and saw a method called
1  
glTranslate()
and it moves the matrix or something instead. How would basic movement work in lwjgl, and how do I keep the movement simple before side scrolling?  Huh
Offline Longarmx
« Reply #1 - Posted 2014-05-05 00:01:26 »

glTranslate(x, y, z)
does pretty much what it says. It translates the matrix. If you want a texture to move left 7 and up 3 then you would say
glTranslate(-7,  3, 0);
I'm not sure I fully understand your question though. Could you explain it more?

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #2 - Posted 2014-05-05 01:21:20 »

glTranslate(x, y, z)
does pretty much what it says. It translates the matrix. If you want a texture to move left 7 and up 3 then you would say
glTranslate(-7,  3, 0);
I'm not sure I fully understand your question though. Could you explain it more?

I mean how would I use this in a keypress event. Such as if up is pressed it moves up at a certain speed
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #3 - Posted 2014-05-05 01:24:25 »

Some pseudo code for you:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
float dx = 0;
float dy = 0;
float dz = 0;

// Moves at a speed of 3
if(moveRightKeyPressed)
{
     dx = 3;
}

if(moveDownKeyPressed)
{
     dy = -3;
}

if(moveCloserKeyPressed)
{
     dx = 3;
}

glTranslate(dx, dy, dz);

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #4 - Posted 2014-05-05 01:26:41 »

Some pseudo code for you:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
float dx = 0;
float dy = 0;
float dz = 0;

// Moves at a speed of 3
if(moveRightKeyPressed)
{
     dx = 3;
}

if(moveDownKeyPressed)
{
     dy = -3;
}

if(moveCloserKeyPressed)
{
     dx = 3;
}

glTranslate(dx, dy, dz);


Yes! this is what I was looking for. After seeing your other post on the guy asking about slick, I thought Java2D was a great intro to game dev.

So now that I have this covered, do you have any good math sites to explain what matrixes are. If you can explain in detail that would be great. I havn't covered this kind of material in school yet.
Offline Longarmx
« Reply #5 - Posted 2014-05-05 01:45:24 »

Matrices basically just encapsulate data. They have special rules on how you can transform them. The basic idea is that you can create a single matrix to represent a series of transformations (translations, rotations, scaling). You can then multiply vectors (representing object positions) by that matrix to transform that point into a different spot.

Link 1
Link 2

Basically just google 'matrix tutorial.' You will probably have to see how this is used in code to get how matrices are used.

The main example I can think of is in a shader.
1  
2  
3  
4  
5  
6  
7  
8  
uniform mat4 transformation;

in vec3 vertex;

void main()
{
     gl_Position = vertex * transformation;
}


Don't worry if this all flies over your head. If you're just using legacy (which you are if you're using glTransform) then opengl will handle all of this for you.

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #6 - Posted 2014-05-05 02:02:13 »

lastly, with glTranslate; how do I make each texture move itself instead of the whole matrix or screen. I have 2 images both sharing glTranslate and moving at the same direction.  I apologize if the image doesn't work. I don't know how to post mini recordings of code running besides YouTube.
Offline Longarmx
« Reply #7 - Posted 2014-05-05 02:11:53 »

lastly, with glTranslate; how do I make each texture move itself instead of the whole matrix or screen. I have 2 images both sharing glTranslate and moving at the same direction.   I apologize if the image doesn't work. I don't know how to post mini recordings of code running besides YouTube.

You would use glPushMatrix() and glPopMatrix(). These two functions basically put a new matrix onto the stack and then remove the top matrix. If you ever want to get back to the main (modelview) matrix then you can call
glLoadIdentity()


1  
2  
3  
4  
5  
6  
7  
8  
9  
glPushMatrix();
glTranslate(x, y, z);
drawObject(); // However you accomplish this
glPopMatrix();

glPushMatrix();
glTranslate(x, y, z);
drawObject2(); // Draw the second object
glPopMatrix();

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #8 - Posted 2014-05-05 02:15:09 »


1  
2  
3  
4  
5  
6  
7  
8  
9  
glPushMatrix();
glTranslate(x, y, z);
drawObject(); // However you accomplish this
glPopMatrix();

glPushMatrix();
glTranslate(x, y, z);
drawObject2(); // Draw the second object
glPopMatrix();


Would I still need the
1  
glBegin()
and
1  
glEnd()
methods for this?
Offline Longarmx
« Reply #9 - Posted 2014-05-05 02:16:39 »

Would I still need the
1  
glBegin()
and
1  
glEnd()
methods for this?

You put these where the drawObject() goes.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #10 - Posted 2014-05-05 02:24:05 »

Would I still need the
1  
glBegin()
and
1  
glEnd()
methods for this?

You put these where the drawObject() goes.

I think I understand where your going with this but the textres aren't moving. In my !Display.IsClosed loop I called 2 of these:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
 
                     glPushMatrix();
            glTranslated(1, 1, 0);
           
            glBegin(GL_QUADS);

                        glTexCoord2f(0, 0); glVertex2i(100, 100); // Upper-left
                        glTexCoord2f(1, 0); glVertex2i(150, 100); // Upper-right
                        glTexCoord2f(1, 1); glVertex2i(150, 150); // Bottom-right
                        glTexCoord2f(0, 1); glVertex2i(100, 150); // Bottom-left
                       
            glEnd();
                        glPopMatrix();


Assuming already created the texture and binded it, what would make this incorrect?
Offline trollwarrior1
« Reply #11 - Posted 2014-05-05 04:43:37 »

Why are you using matrices to translate each object, if you're sending vertices every time you render? Wouldn't it be more logical to send x,y,width,height

1  
2  
3  
4  
5  
6  
7  
8  
            glBegin(GL_QUADS);

                        glTexCoord2f(0, 0); glVertex2i(x, y); // Upper-left
                        glTexCoord2f(1, 0); glVertex2i(x + width, y); // Upper-right
                        glTexCoord2f(1, 1); glVertex2i(x + width, y + height); // Bottom-right
                        glTexCoord2f(0, 1); glVertex2i(x, y + height); // Bottom-left
                       
            glEnd();
Offline Longarmx
« Reply #12 - Posted 2014-05-05 05:15:29 »

glTranslate would be a better  option for transforming groups of objects the same way. If you want to transform each object individually then setting the x and y for each vertex would be easier.

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #13 - Posted 2014-05-05 20:04:48 »

It's working now.  Grin But could I create a player class with its' private x and y and in my main drawing class just call player.getx and player.gety? I'm getting the hang of things, I created some pseudo code:

1  
2  
3  
4  
5  
6  
             glBegin(GL_QUADS);
                        glTexCoord2f(0, 0); glVertex2i(player.getx(), player.gety());
                        glTexCoord2f(1, 0); glVertex2i(player.getx() + width, player.gety());
                        glTexCoord2f(1, 1); glVertex2i(player.getx() + width,  player.gety() + height);
                        glTexCoord2f(0, 1); glVertex2i(player.getx(), player.gety() + height);
            glEnd();


I would be calling the getters and setters in the player class, but this seems correct right?

Also, in my glBegin; do I have to draw everything in between begin and end? I can't have more than one begins and ends?
Offline opiop65

JGO Kernel


Medals: 160
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #14 - Posted 2014-05-05 20:19:30 »

You can have more than one begin and end pair, but try to minimize the amount of calls you make to them. I also have to tell you, the OpenGL code you're using right now is very outdated, and you would probably be better off learning modern (3.x or so) OpenGL because you'll have to move away from the code you are using right now.

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #15 - Posted 2014-05-05 20:38:10 »

You can have more than one begin and end pair, but try to minimize the amount of calls you make to them. I also have to tell you, the OpenGL code you're using right now is very outdated, and you would probably be better off learning modern (3.x or so) OpenGL because you'll have to move away from the code you are using right now.

So where should I learn it then? Every tutorial ive seen uses something like this except usually with a constructor
Offline Spacebeans
« Reply #16 - Posted 2014-05-05 22:03:45 »

So where should I learn it then? Every tutorial ive seen uses something like this except usually with a constructor

Knowing Opiop56, he will pretty much recommend advanced stuff to everyone whenever he sees deprecated OpenGL methods. Smiley

Basically glBegin and glEnd are very old. People don't use them anymore, because it sends the vertex data (points) to the graphics card inefficiently. (Every frame, Which is very, very slow)
glBegin and glEnd are Immediate mode. While everything else is retained mode.

You don't really have to worry about all this new 3.x stuff yet, but if you want to get you feet wet,  Wikipedia states:

Quote from: Wikipedia
A Vertex Buffer Object (VBO) is an OpenGL feature that provides methods for uploading vertex data (position, vector, color, etc.) to the video device for non-immediate-mode rendering. VBOs offer substantial performance gains over immediate mode rendering primarily because the data resides in the video device memory rather than the system memory and so it can be rendered directly by the video device. (This is retained mode)

You can get some really awesome tutorials on that here:

http://www.opengl-tutorial.org/beginners-tutorials/
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-4-a-colored-cube/
Offline Longarmx
« Reply #17 - Posted 2014-05-05 22:06:45 »

Or you can even look on the lwjgl wiki under the OpenGL 3.2 and newer section to get you started.

Offline opiop65

JGO Kernel


Medals: 160
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #18 - Posted 2014-05-05 22:14:19 »

Where did you get the term retained mode...?
And I recommend it only because everyone recommended it to me when I was starting out, and I ignored them. I spent a year learning deprecated code only to have to relearn OpenGL completely. Trust me, old immediate mode isn't worth the time.

Offline Spacebeans
« Reply #19 - Posted 2014-05-05 22:19:38 »

Where did you get the term retained mode...?

Mah bad. I thought it was the opposite of immediate. I just googled "immediate mode vs ?" and it had "retained mode" in the search.

- I don't even think there is a name for that, is there?
Offline Longarmx
« Reply #20 - Posted 2014-05-05 22:21:11 »

- I don't even think there is a name for that, is there?

Improved mode? Do everything yourself mode? Power mode?

I just usually say it's the modern version.

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #21 - Posted 2014-05-05 22:59:51 »

No idea about that mode thing but I was pretty angry I couldn't get some code to work and you said it was outdated. There was nothing I could do since I have a slow laptop with old graphics card. I did fix my code based on answers though.  Yawn
Offline Longarmx
« Reply #22 - Posted 2014-05-05 23:04:51 »

Do you know what version that gfx card can support? Even if it just supports OpenGL 2 then there are some nice things that you can do in code.

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #23 - Posted 2014-05-05 23:16:09 »

Do you know what version that gfx card can support? Even if it just supports OpenGL 2 then there are some nice things that you can do in code.

Actually I haven't checked. now I realized what you guys mean. To test it, should I just bring the GL11 up and run until I get a graphics error?
Offline Longarmx
« Reply #24 - Posted 2014-05-05 23:17:34 »

Or you can just run this code instead Wink

1  
System.out.println(GL11.glGetString​(GL11.GL_VERSION​));

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #25 - Posted 2014-05-05 23:24:44 »

1  
2  
3  
4  
[quote author=Longarmx link=topic=33044.msg309982#msg309982 date=1399331854]
Or you can just run this code instead ;)

[code]System.out.println(GL11.glGetString​(GL11.GL_VERSION​));

[/quote]

It prints: code]2.1.0 - Build 8.15.10.2555[/code] in the console.
Offline opiop65

JGO Kernel


Medals: 160
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #26 - Posted 2014-05-05 23:26:11 »

Wow... that's quite low. What graphics card (or more likely integrated chipset) do you have?

Offline Longarmx
« Reply #27 - Posted 2014-05-05 23:29:16 »

That means that you can use Shaders and VBOs for rendering (Opengl V2). These are considered modern techniques in comparison to legacy Opengl. Obviously, you won't be able to do all that the OpenGL 3+ tutorials teach you, but it is still quite an improvement.

Offline Mr.CodeIt

Junior Devvie


Exp: 1 year



« Reply #28 - Posted 2014-05-06 00:01:57 »

Wow... that's quite low. What graphics card (or more likely integrated chipset) do you have?

Yeah it's about 2 or 3 years old. Where do I check  its' graphics card.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!