I have a problem with what seems to be binding the textures to a shape. When I do so, I get a white shape of the correct dimensions, the color given to it by Color.white.bind().
GraphicsManager.java
package com.jackwilsdon.spectrun;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
public class GraphicsManager {
final static int WIDTH = 800;
final static int HEIGHT = 600;
private static Texture cloudTexture = null;
public static void initDisplay() throws LWJGLException
{
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create();
}
public static void initOpenGL()
{
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, WIDTH, 0, HEIGHT, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
public static void loadTextures()
{
Texture currentObject = null;
try {
currentObject = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("./resources/cloud.png"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Texture loaded: "+currentObject);
System.out.println(">> Image width: "+currentObject.getImageWidth());
System.out.println(">> Image height: "+currentObject.getImageHeight());
System.out.println(">> Texture width: "+currentObject.getTextureWidth());
System.out.println(">> Texture height: "+currentObject.getTextureHeight());
System.out.println(">> Texture ID: "+currentObject.getTextureID());
cloudTexture = currentObject;
}
public static void DrawRectangle(int x, int y, int width, int height)
{
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(x,y);
GL11.glVertex2f(x+width,y);
GL11.glVertex2f(x+width,y+height);
GL11.glVertex2f(x,y+height);
GL11.glEnd();
}
public static void DrawRectangle(int x, int y, int width, int height, int red, int green, int blue)
{
GL11.glColor3ub((byte)red, (byte)green, (byte)blue);
DrawRectangle(x, y, width, height);
}
public static Vector2f DrawCloud(int x, int y)
{
cloudTexture.bind();
int width = cloudTexture.getImageWidth();
int height = cloudTexture.getImageHeight();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(x,y);
GL11.glVertex2f(x+width,y);
GL11.glVertex2f(x+width,y+height);
GL11.glVertex2f(x,y+height);
GL11.glEnd();
return new Vector2f(cloudTexture.getImageWidth(), cloudTexture.getImageHeight());
}
}
I suspect it has something to do with my initOpenGL() method, as in an example I have looked at (http://ninjacave.com/slickutil1), theirs is very different. Just copying theirs into mine gives unexpected results (black screen). Is something missing from my initOpenGL() method?
EDIT: The loadTextures() method outputs the correct image dimensions, but the texture's dimensions are different, what does this mean?
EDIT 2: The PNG is not the problem, I've tried 2 others to find the same result.
A new problem has arisen after fixing my code, by setting the texture coordinates.
I now get a weird effect, like this; i.imgur.com/5lr79.png. The image is no longer full size, and has a black box to the bottom left of it.
GraphicsManager.java
package com.jackwilsdon.spectrun;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
public class GraphicsManager {
final static int WIDTH = 800;
final static int HEIGHT = 600;
private static Texture cloudTexture = null;
public static void initDisplay() throws LWJGLException
{
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create();
}
public static void initOpenGL()
{
GL11.glEnable(GL11.GL_TEXTURE);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, WIDTH, 0, HEIGHT, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
public static void loadTextures()
{
Texture currentObject = null;
try {
currentObject = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("./resources/cloud.png"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Texture loaded: "+currentObject);
System.out.println(">> Image width: "+currentObject.getImageWidth());
System.out.println(">> Image height: "+currentObject.getImageHeight());
System.out.println(">> Texture width: "+currentObject.getTextureWidth());
System.out.println(">> Texture height: "+currentObject.getTextureHeight());
System.out.println(">> Texture ID: "+currentObject.getTextureID());
cloudTexture = currentObject;
}
public static void DrawRectangle(int x, int y, int width, int height)
{
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(x,y);
GL11.glVertex2f(x+width,y);
GL11.glVertex2f(x+width,y+height);
GL11.glVertex2f(x,y+height);
GL11.glEnd();
}
public static void DrawRectangle(int x, int y, int width, int height, int red, int green, int blue)
{
GL11.glColor3ub((byte)red, (byte)green, (byte)blue);
DrawRectangle(x, y, width, height);
}
public static Vector2f DrawCloud(int x, int y)
{
cloudTexture.bind();
int width = cloudTexture.getImageWidth();
int height = cloudTexture.getImageHeight();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(1,1);
GL11.glVertex2f(x,y);
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(x+width,y);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(x+width,y+height);
GL11.glTexCoord2f(1,0);
GL11.glVertex2f(x,y+height);
GL11.glEnd();
return new Vector2f(cloudTexture.getImageWidth(), cloudTexture.getImageHeight());
}
}
It doesn't help that you aren't calling GL11.glEnable( GL11.GL_TEXTURE ) and you also aren't setting any texture coordinates.
Both of these will rather mess up your ability to see a texture on the quad ...
I do believe the call to bind() needs to be between your glBegin() and glEnd() call to make it stick. The dimension problem is somewhat more odd - perhaps your texture dimensions are not a power of 2 and it is being translated by the driver?
You didnt enable gl_TEXTURE_2D first of all. Second, you need to call .bind() inside glBegin() and your glEnd(). Third, you need texture coordinates. So, for the top left edge it would be 'glTexCoord(0, 0)', the next would be '(1, 0)' and then '(1, 1)' and lastly '(0, 1)'
Don't forget to call TextureImpl.unbind when needed.
Related
I wanted to add a block that, like in mario, a mushroom appears after a jump and the block changes. However, this block does nothing and I pass through it. The program works fine, but it seems to me there is an error somewhere.
package com.mario.tile;
import java.awt.Graphics;
import com.mario.Game;
import com.mario.Handler;
import com.mario.Id;
import com.mario.entity.powerup.Mushroom;
import com.mario.gfx.Sprite;
public class PowerUpBlock extends Tile {
private Sprite powerUp;
private boolean poppedUp = false;
private int spriteY = getY();
public PowerUpBlock(int x, int y, int width, int height, boolean solid, Id id, Handler handler, Sprite powerUp) {
super(x, y, width, height, solid, id, null);
this.powerUp = powerUp;
}
public void render(Graphics g) {
if(!poppedUp) g.drawImage(powerUp.getBufferedImage(),x,spriteY,width,height,null);
if(!activated) g.drawImage(Game.powerUp.getBufferedImage(),x,y,width,height,null);
else g.drawImage(Game.usedPowerUp.getBufferedImage(),x,y,width,height,null);
}
public void tick() {
if(activated&&!poppedUp) {
spriteY--;
if(spriteY<=y-height) {
handler.addEntity(new Mushroom(x,spriteY,width,height,Id.mushroom,handler));
poppedUp = true;
}
}
}
}
Can you tell me what I did wrong?
I say thank you in advance.
I am encountering a problem whenever I draw a GL_POINT, it draws a circle while all the examples I am using show a square appear I have done some research and it appears it might be anti aliasing but nothing I try fixes it.
package main.ui;
import static com.jogamp.opengl.GL4.*;
import java.nio.FloatBuffer;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GL4;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLContext;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.awt.GLCanvas;
public class CanvasHandler extends GLCanvas implements GLEventListener {
private static final long serialVersionUID = 1L;
private int rendering_program;
private int[] vao = new int[1];
public CanvasHandler(int x, int y, int width, int height) {
setBounds(x, y, width, height);
setVisible(true);
addGLEventListener(this);
}
#Override
public void display(GLAutoDrawable arg0) {
GL4 gl = (GL4) GLContext.getCurrentGL();
float colors[] = {1.0f, 0.0f, 0.0f, 1.0f};
FloatBuffer color = Buffers.newDirectFloatBuffer(colors);
gl.glClearBufferfv(GL_COLOR, 0 , color);
//Drawing handler
gl.glUseProgram(rendering_program);
gl.glPointSize(400f);
gl.glDrawArrays(GL_POINTS, 0, 1);
//System.out.println(GL_POINT);
}
#Override
public void init(GLAutoDrawable arg0) {
GL4 gl = (GL4) GLContext.getCurrentGL();
rendering_program = createShaderProgram();
gl.glGenVertexArrays(vao.length, vao, 0);
gl.glBindVertexArray(vao[0]);
}
private int createShaderProgram() {
GL4 gl = (GL4) GLContext.getCurrentGL();
String[] rawVertexShader = {
"#version 430 \n",
"void main(void) \n",
"{ gl_Position = vec4(0.0, 0.0, 0.0, 1.0); } \n"
};
String[] rawFragmentShader = {
"#version 430 \n",
"out vec4 color; \n",
"void main(void) \n",
"{ \n",
//"if(gl_FragCoord.x < 200) color = vec4(0.0, 1.0f, 0.0, 1.0f); else color = vec4(0.0f,0.0f,1.0f,1.0f);",
"color = vec4(0.0f, 0.0f, 1.0f, 1.0f);",
"} \n"
};
int vertexShader = gl.glCreateShader(GL_VERTEX_SHADER);
int fragmentShader = gl.glCreateShader(GL_FRAGMENT_SHADER);
gl.glShaderSource(vertexShader, rawVertexShader.length, rawVertexShader, null, 0);
gl.glShaderSource(fragmentShader, rawFragmentShader.length, rawFragmentShader, null, 0);
gl.glCompileShader(vertexShader);
gl.glCompileShader(fragmentShader);
int programid = gl.glCreateProgram();
gl.glAttachShader(programid, vertexShader);
gl.glAttachShader(programid, fragmentShader);
gl.glLinkProgram(programid);
gl.glDeleteShader(vertexShader);
gl.glDeleteShader(fragmentShader);
return programid;
}
#Override
public void dispose(GLAutoDrawable arg0) {
}
#Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
}
}
The way it starts is in another class.
Try disabling point smoothing by calling the following before you render the points:
glDisable(GL_POINT_SMOOTH);
That being said, note that point drawing is quite driver-dependent, especially for large sizes (I have seen drivers that won't even go above a point size of 16ish). In general, GL_POINTS should only be used as a quick debug facility, and typically for much smaller sizes. When you need a rectangle, use GL_QUADS (with four vertices, one for each corner).
Currently, I am able to move the box to the left and right through the display boundary, but I am unable to figure out how to move the box up and down. I would like the box to navigate in a circle around the display, e.g move right, then down, then to the left, then up, then continuously moving throughout the display. Here is my code for my entity class:
import java.awt.Rectangle;
import org.lwjgl.opengl.GL11;
class Entity
{
private static enum State { START, LEFT, RIGHT, UP, DOWN};
private Rectangle box;
private State state;
private float speed; // pixels / ms
public Entity(float speed)
{
box = new Rectangle(10, 10, 10, 10);
state = State.START;
this.speed = speed;
}
public void draw()
{
float x = (float)box.getX();
float y = (float)box.getY();
float w = (float)box.getWidth();
float h = (float)box.getWidth();
// draw the square
GL11.glColor3f(0,1,0);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(x, y);
GL11.glVertex2f(x+w, y);
GL11.glVertex2f(x+w, y+w);
GL11.glVertex2f(x, y+w);
GL11.glEnd();
}
public void update(int delta)
{
switch (state)
{
case START:
state = State.RIGHT;
case RIGHT:
box.translate((int)(speed*delta), 0);
if (box.getX() >= 800)
{
state = State.LEFT;
}
break;
case LEFT:
box.translate((int)(-speed*delta), 0);
if (box.getX() <= 0)
{
state = State.RIGHT;
}
break;
}
}
}
Here is my code for GameLoop:
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.input.Keyboard;
import org.lwjgl.LWJGLException;
public class GameLoop
{
public static final int TARGET_FPS=100;
public static final int SCR_WIDTH=800;
public static final int SCR_HEIGHT=600;
public static void main(String[] args) throws LWJGLException
{
initGL(SCR_WIDTH, SCR_HEIGHT);
Entity e = new Entity(.1f);
long time = (Sys.getTime()*4000)/Sys.getTimerResolution(); // ms
while (! Display.isCloseRequested())
{
long time2 = (Sys.getTime()*4000)/
Sys.getTimerResolution(); // ms
int delta = (int)(time2-time);
System.out.println(delta);
e.update(delta);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
e.draw();
// UPDATE DISPLAY
Display.update();
Display.sync(TARGET_FPS);
time = time2;
}
Display.destroy();
}
public static void initGL(int width, int height) throws LWJGLException
{
// open window of appropriate size
Display.setDisplayMode(new DisplayMode(width, height));
Display.create();
Display.setVSyncEnabled(true);
// enable 2D textures
GL11.glEnable(GL11.GL_TEXTURE_2D);
// set "clear" color to black
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// enable alpha blending
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// set viewport to entire window
GL11.glViewport(0,0,width,height);
// set up orthographic projectionr
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0, 1, -1);
// GLU.gluPerspective(90f, 1.333f, 2f, -2f);
// GL11.glTranslated(0, 0, -500);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
}
Any help would be appreciated. I also need to have the box change colors every time it changes direction.
Correct me if i'm wrong but i think you just need to use box.translate(0,value) to move your Rectangle up or down. Just adapt your left-right movement to the y value of the box. You could also use the State to determine which color it should be drawn in.
I have a 10000x10000 BufferedImage and I'm looking to draw only part of it to a Canvas, is there a way to do this using args such as:
x, y, width, height ?
So for example, drawImage(img, x, y, width, height) would draw a rectangle from the image starting at (x, y) and having (width, height) as the dimensions?
EDIT:
I'm going to re- word this question:
I have a 10000x10000 image and I only want to display a portion of it on the screen, the problem with just offsetting it by x and y is that this still causes lag as the entire image is being rendered, just most of it off canvas. How can I basically make it so that the entire image is rendered but I can scroll around it without causing the canvas to lag?
I have a 10000x10000 BufferedImage and I'm looking to draw only part
of it to a Canvas, is there a way to do this using args such as:
Don't use canvas for custom painting in java. use JComponent or JPanel instead. It has a nice function paintComponent(Graphics g), override it and paint your image inside with g.drawImage(x, y, width, height, observer);
Swing graphics has Graphics.clipRect(int x, int y, int width, int height) to bound the area rectangle to which you wish to draw prior to drawing the image.
Edit (In response to your edited question):
First approach is to use BufferedImage..getSubimage(x, y, width, height) to get a sub image with specified rectangle region. It is faster.
BufferedImage img = ImageIO.read(new File("file"));
img = img.getSubimage(50, 50, 500, 500); // 500 x 500
This function will give you a new image cropped with the rectangle(x, y, width, height) of your original image you specified. Use the returned image to draw on your component.
Tutorial resource: Clipping the Drawing Region
Demo: Demonstrating clipping Image with Animation:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.logging.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.Timer;
class MyCanvas extends JPanel implements ActionListener
{
public BufferedImage buffImg;
public Rectangle rectangle;
Random random;
long lastTimeChanged;
int dirX = 1, dirY = 1;
volatile static boolean imageLoading = true;
public MyCanvas() {
random = new Random();
rectangle = new Rectangle(50, 50, 250, 250);
lastTimeChanged = System.currentTimeMillis();
setBackground(Color.WHITE);
}
#Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if(imageLoading)
{
showWaitForLoading(g);
return;
}
g.clipRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
g.drawImage(buffImg, 0, 0, getWidth(), getHeight(), this);
}
public void showWaitForLoading(Graphics g)
{
Graphics2D g2d = (Graphics2D)g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.DARK_GRAY);
g2d.fillRoundRect(getWidth()/2-100, getHeight()/2-15, 200, 30, 30, 30);
g2d.setColor(Color.WHITE);
g2d.drawString("Loading image...", getWidth()/2 - 45, getHeight()/2 + 3 );
g2d.dispose();
}
#Override
public void actionPerformed(ActionEvent e) {
long endTime = System.currentTimeMillis();
if(endTime - lastTimeChanged > 500)
{
dirX = random.nextInt(2) == 0 ? -1 : 1;
dirY = random.nextInt(2) == 0 ? -1 : 1;
lastTimeChanged = endTime;
}
if(rectangle.x < 0)dirX = 1;
else if(rectangle.x + rectangle.width > getWidth())dirX = -1;
if(rectangle.y < 0)dirY = 1;
else if(rectangle.y + rectangle.height > getHeight())dirY = -1;
rectangle.x = rectangle.x + dirX * 10;
rectangle.y = rectangle.y + dirY * 10;;
repaint();
}
}
public class CustomPainting {
public static void main(String[] args) throws IOException {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
final MyCanvas canvas = new MyCanvas();
JFrame frame = new JFrame();
frame.setSize(new Dimension(500, 500));
frame.add(canvas);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Timer timer = new Timer(200, canvas);
timer.start();
new Thread()
{
public void run()
{
try {
canvas.buffImg = ImageIO.read(new URL("http://images6.fanpop.com/image/photos/33400000/Cute-Panda-beautiful-pictures-33434826-500-500.jpg"));
MyCanvas.imageLoading = false;
} catch (IOException ex) {
Logger.getLogger(CustomPainting.class.getName()).log(Level.SEVERE, null, ex);
}
}
}.start();
}
});
}
}
You can scale or draw a part of an image using Graphics.drawImage as mentioned another answer and according to Java documentation, ImageObserver argument is not needed for BufferedImage so you can just pass null.
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html
However, my choice would be the clipping drawing region of image instead.
Here is an example you can try:
Graphics2D g = BufferedImage.getGraphics;
g.setClip(x, y, width, height);
g.drawImage(sx, sy, x - sx, y - sy, null );
Yes there is: drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
I've been trying to write a game engine in lwjgl and I've come across an issue with rendering and I'd like a bit of help. Basically, I've followed some steps in the lwjgl-basics (mattdesl on GitHub) and produced a Texture class and a section in my renderer that work except that they don't render a texture. Here's the code...
public void drawTexturedRectangle(float x1, float y1, float w, float h, Texture t){
t.bind();
GL11.glColor4f(1.0f, 0, 1.0f, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(x1, y1);
GL11.glTexCoord2f(1.0f, 0);
GL11.glVertex2f(x1 + w, y1);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex2f(x1 + w, y1 + h);
GL11.glTexCoord2f(0, 1.0f);
GL11.glVertex2f(x1, y1 + h);
GL11.glEnd();
}
That's where it renders. Here's the Texture class:
package com.nightfall.morningside;
import java.io.*;
import java.net.URL;
import java.nio.ByteBuffer;
import de.matthiasmann.twl.utils.*;
import org.lwjgl.opengl.*;
import org.lwjgl.opengl.GL12.*;
import org.lwjgl.BufferUtils;
public class Texture {
public int width;
public int height;
public int id;
public Texture(URL pathToTexture){
try {
InputStream pngstream = pathToTexture.openStream();
PNGDecoder pngdecoder = new PNGDecoder(pngstream);
width = pngdecoder.getWidth();
height = pngdecoder.getHeight();
int bpp = 4;
ByteBuffer buffer = BufferUtils.createByteBuffer(bpp * width * height);
pngdecoder.decode(buffer, width * bpp, PNGDecoder.Format.RGBA);
buffer.flip();
id = GL11.glGenTextures();
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void bind(){
GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
}
}
The TexturedRectangle class:
package com.nightfall.morningside.geometry;
import com.nightfall.morningside.Texture;
import com.nightfall.morningside.Textured;
public class TexturedRectangle extends Rectangle implements Textured{
public Texture texture;
public TexturedRectangle(float xone, float yone, float w, float h, Texture t) {
super(xone, yone, w, h);
texture = t;
}
public Texture getTexture() {
return texture;
}
}
The Rectangle class:
package com.nightfall.morningside.geometry;
public class Rectangle {
private float x1;
private float y1;
private float width;
private float height;
public Rectangle(float xone, float yone, float w, float h){
x1 = xone;
y1 = yone;
width = w;
height = h;
}
public float getX1(){
return x1;
}
public float getY1(){
return y1;
}
public float getHeight(){
return height;
}
public float getWidth(){
return width;
}
public Point getLocation(){
return new Point(x1, y1);
}
}
And the Textured interface:
package com.nightfall.morningside;
public interface Textured {
public Texture getTexture();
}
And the Point class:
package com.nightfall.morningside.geometry;
public class Point {
private float x1;
private float y1;
public Point(float x, float y){
x1 = x;
y1 = y;
}
public float getX(){
return x1;
}
public float getY(){
return y1;
}
}
I hope this is everything. I believe it's an issue in the way I'm rendering but maybe there's an issue in where I load textures.
If you need anything else, I'll put it up for you.
Thanks.
Texture are disable by default. When you want to render a textured primitive (a textured quad for instance), you must activate texturing with
glEnable(GL_TEXTURE2D);
glBindTexture(GL_TEXTURE_2D, textureId);
The first line tells openGL to use texturing, the second specify which texture you want to use.
To stop using the texture, you can:
Bind zero to GL_TEXTURE_2D : glBindTexture(GL_TEXTURE_2D, 0); or
Disable GL_TEXTURE_2D : glDisable(GL_TEXTURE_2D);
edit, I forgot all the GLxx. prefixes (static import in my codes)