The visible image is 793x500, while it should be 1270x710, which s exactly (well, rounded to whole pixels) the same ratio as 1280/2048 and 720/1024.To me, this looks like your texture loading code is trying to be intelligent - for a 90s scenario: It creates textures of the next greater power-of-two value (early GPUs did not support non-power-of-two textures), and just uses the sub-image. So you can either change the texcoords (try 1280.f/2048.f instead of 1.0 for the width, and 720.f/1024/f instead of 1.0 for the height), or you some texture loading code which is targeting GPUs from the current millenium.
Slick texture has lines and does not fit
質問
Today I have encountered a problem while making my game using LWJGL and Slick-Util
My texture is 1280x720 but when I bind it, it looks like this, even though my window is 1280x720:
Screenshot http://puu.sh/8n2fN.png
Cube Renderer:
package org.cel.api;
import org.lwjgl.opengl.GL11;
public class CubeRenderer
{
public static void renderCube(float x, float y, float width, float height)
{
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(x,y);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(x+width,y);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(x+width,y+height);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(x,y+height);
GL11.glEnd();
GL11.glDisable(GL11.GL_TEXTURE_2D);
}
}
GuiMainMenu
package org.cel.client.gui;
import org.cel.api.CubeRenderer;
import org.cel.api.IGui;
import org.cel.api.Resources;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.TextureImpl;
public class GuiMainMenu implements IGui
{
@Override
public void update()
{
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, Resources.getTexture("mainMenu").getTextureID());
GL11.glColor3f(1f, 1f, 1f);
CubeRenderer.renderCube(0, 0, 1270, 710);
TextureImpl.bindNone();
}
@Override
public void init()
{
}
@Override
public void keyboardEvent(int key, boolean state)
{
}
@Override
public void mouseEvent(int button, boolean state, int x, int y)
{
System.out.println(x + " : " + y);
}
}
Main Class
package org.cel;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_SMOOTH;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL11.glClearDepth;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glShadeModel;
import static org.lwjgl.opengl.GL11.glViewport;
import org.cel.api.FontRenderer;
import org.cel.api.IGui;
import org.cel.api.Resources;
import org.cel.client.gui.GuiMainMenu;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class Cel
{
public static Cel instance;
public IGui currentGui;
public FontRenderer fontRenderer;
public static void main(String[] args)
{
instance = new Cel();
instance.main(args, true);
}
public void main(String args[], boolean isInstance)
{
try
{
Display.setDisplayMode(new DisplayMode(1280, 720));
Display.setTitle("Cel");
Display.create();
initGL();
Resources.registerTexture("mainMenu", "gui/MainMenu.png");
}
catch(Exception ex)
{
ex.printStackTrace();
System.exit(-1);
}
gameLoop(args);
}
public void gameLoop(String args[])
{
currentGui = new GuiMainMenu();
while(!Display.isCloseRequested())
{
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
if(!currentGui.isInitialized)
{
currentGui.init();
}
currentGui.update();
input();
Display.update();
Display.sync(120);
}
}
private void initGL() throws LWJGLException
{
glEnable(GL11.GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1);
glViewport(0, 0, 1280, 720);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GL11.glOrtho(0, 1280, 720, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
fontRenderer = new FontRenderer();
}
public void input()
{
while(Keyboard.next())
{
currentGui.keyboardEvent(Keyboard.getEventKey(), Keyboard.getEventKeyState());
}
while(Mouse.next())
{
currentGui.mouseEvent(Mouse.getEventButton(), Mouse.getEventButtonState(), Mouse.getX(), Mouse.getY());
}
}
}
解決
他のヒント
It could be that you keep turning off GL_TEXTURE_2D
, but attempt to bind the texture while it is off. Try removing theglEnable
+ glDisable
in your CubeRenderer.
所属していません StackOverflow