Java Game Programming - Texture Translation

preview_player
Показать описание
Today we're giving our drawing method a facelift so that it can draw textures!
Рекомендации по теме
Комментарии
Автор

Really love these tutorials, thanks so much for teaching this

periodicdinamo
Автор

Cross Coast Gaming Hey mate... I've been following your tutorials for a while now and i have a bit of a problem... Whenever i type "glEnable(GL_TEXTURE_2D)" like you did on 1:51 i keep getting an error saying "GL_TEXTURE_2D cannot be resolved to a variable" and it's been driving me crazy. I tried everything i could think of, i even retyped it over and over again just to make sure but it simply wont work... any thoughts?
PS: I really enjoy your tutorials, they are the easiest to follow and learn from... God bless!

KappoDB
Автор

Hey, thanks for putting these out here. I'm doing a project right now where a lot of these concepts are tantamount to my success. My only complaint at this point is something that others pointed out. You changed some of the imports prior to this episode, so it threw some errors. I have not watched farther in the series yet and don't know if that continues, but it's a good thing to address (even if it's in annotations in Youtube). Thanks again!

JordanSemrow
Автор

Good tutorials man!
I been looking in to java alot but never realy got it right.
Your tutorials did it for me and just want to keep going and explore more!
Looking forward to more from you!

Will you show how to build the game to a runnable exe file when the game is done and ready?

mrChewiie
Автор

Can you make a video about using sprite sheets?

owenradcliffe
Автор

At 2:16 it tells me that Texture cannot be resolved to a type, I don't know what I did wrong please help me

thevaxia
Автор

Yo this comment is waaay late, but, that was a nice visual aid. Thank you for your great teaching and consideration <3

xfreii
Автор

It keeps saying that glEnable(GL_TEXTURE_2D) needs to be resolved to a variable. What I'm I doing wrong

Edit: nvm I figured it out, the importing messed up

TheAirStatus
Автор

For some reason, when I change my height and width to the new dimensions, the scaling on whatever I have changes.  Such as, with the squares in the videos before, they became rectangles and I don't know why.  I ignored it and continued with your videos, but it eventually breaks and this is where I'm stuck.  I'm not sure if it's particularly this video, but this is where I encountered it first.
Ignore the DrawLine and DrawSquare methods, those were for trying to find out where everything started breaking.

Here's my code :

package helpers;

import static org.lwjgl.opengl.GL11.*;

import java.io.IOException;
import java.io.InputStream;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import
import
import

public class artist {

    public static final int WIDTH = 1280, HEIGHT = 960;

    public static void DrawLine() {
        glBegin(GL_LINES);
        glVertex2f(10, 10);
        glVertex2f(100, 100);
        glEnd();
    }
    
    public static void DrawSquare(float x, float y, float width, float height) {
        glBegin(GL_QUADS);
        glVertex2f(x, y);
        glVertex2f(x+width, y);
        glVertex2f(x+width, y+height);
        glVertex2f(x, y+height);
        glEnd();
    }

    public static void BeginSession() {
        Display.setTitle("Game");
        try {
            Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
            Display.create();
        } catch (LWJGLException e) {
            e.printStackTrace();
        }

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_TEXTURE_2D);
    }

    public static void DrawQuad(float x, float y, float width, float height) {
        glBegin(GL_QUADS);
        glVertex2f(x, y); // topleft
        glVertex2f(x + width, y); // top right
        glVertex2f(x + width, y + height); // bot right
        glVertex2f(x, y + height); // bot left
        glEnd();

    }

    public static void DrawQuadTex(Texture tex, float x, float y, float width,
            float height) {
        tex.bind();
        glTranslatef(x, y, 0);
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex2f(0, 0);
        glTexCoord2f(1, 0);
        glVertex2f(width, 0);
        glTexCoord2f(1, 1);
        glVertex2f(width, height);
        glTexCoord2f(0, 1);
        glVertex2f(0, height);
        glEnd();
        glLoadIdentity();
    }

    public static Texture LoadTexture(String path, String fileType) {
        Texture tex = null;
        InputStream in =
        try {
            tex = TextureLoader.getTexture(fileType, in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return tex;
    }

    public static Texture QuickLoad(String name) {
        Texture tex = null;
        tex = LoadTexture("res/" + name + ".png", "PNG");
        return tex;
    }
}

pokepokeo
Автор

it keeps saying that glTranslatef(float, float, int) is an undefined method

jeusvelarde
Автор

Hello! if you could read this i need help. my texture import is not working

Mac_attack
Автор

What does the f mean at the end of glVertex2f (and other things)?

jamesx
Автор

*OpenGL*: glBegin(GL_QUADS);
gl.Vertex2f(x, y); ... (you get it)
up to glEnd;
*simple Java*
try{
BufferedImage some_image = ImageIO.read(new File("path"));
}catch(IOException e){
e.printStackTrace();
}
Graphics.drawImage(some_image, x, y, null);
done. for every image you have to draw. done.

n.m.
Автор

I am interested in what you are teaching in this series but I am having a hard time staying tuned in because your voice is very monotone and it's making me sleepy. Just thought I should share this!

Kagesh
Автор

Great tutorials but you have to stop doing things behind the scene bud. Where you start Line 53: public static void Draw I have line 47. You have added some imports that i resolved with just one which is the GL11 one to get my GL_TEXTURE_2D to light up and find its variable. Consider this as a note and not as a whine lol. Other then that, I'm making just great first steps into java. I have no previous experience with it other then playing Minecraft :D So /public static println("Thank You! ;)");

unjoyerplay