本文整理匯總了Java中org.newdawn.slick.opengl.TextureLoader類的典型用法代碼示例。如果您正苦於以下問題:Java TextureLoader類的具體用法?Java TextureLoader怎麽用?Java TextureLoader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TextureLoader類屬於org.newdawn.slick.opengl包,在下文中一共展示了TextureLoader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public int loadTexture(final String fileName) {
Texture texture = null;
try (final FileInputStream inputStream = new FileInputStream(getResourcePath("textures/" + fileName + ".png"))) {
texture = TextureLoader.getTexture("PNG", inputStream);
} catch (final IOException ex) {
LOGGER.error("Exception occurred - {} while loading texture file - {}", ex, fileName);
}
assertTextureNotNullForFileName(texture, fileName);
final int textureId = texture.getTextureID();
textures.add(textureId);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
return textureId;
}
示例2: loadTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public int loadTexture(String fileName) {
Texture texture = null;
try {
texture = TextureLoader.getTexture("PNG", new FileInputStream(Primary.fileHandler.getTexture(fileName)));
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0f);
} catch (Exception e) {
e.printStackTrace();
System.err.println("Tried to load texture " + fileName + ".png , didn't work");
System.exit(-1);
}
textures.add(texture.getTextureID());
return texture.getTextureID();
}
示例3: loadTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public int loadTexture(String fileName) {
Texture texture = null;
try {
texture = TextureLoader.getTexture("PNG", new FileInputStream("res/"+fileName +".png"));
// Mipmapping to lower resolution of distance textures
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
// Changes the level of detail to change the mipmapping to a slightly higher resolution
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, -0.4f);
} catch (IOException e) {
e.printStackTrace();
}
//TODO fix null assertion
int textureID = texture.getTextureID();
textures.add(textureID);
return textureID;
}
示例4: loadTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public int loadTexture(String fileName) {
Texture texture = null;
try {
texture = TextureLoader.getTexture("PNG",
new FileInputStream(MainGameLoop.fileManager.getTextureFile(fileName)));
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0);
if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
float amount = Math.min(4f,
GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT));
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
amount);
} else {
System.out.println("Filter Anisotropic Not Supported");
}
} catch (Exception e) {
e.printStackTrace();
System.err.println("Tried to load texture " + fileName + ".png , didn't work");
System.exit(-1);
}
textures.add(texture.getTextureID());
return texture.getTextureID();
}
示例5: Init
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
@Override
protected void Init() {
try {
GL11.glEnable(GL11.GL_TEXTURE_2D);
Texture button1 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton1.png"), false, GL11.GL_NEAREST);
GUI.AddButton(460, 154, button1.getImageWidth(), button1.getImageHeight(), button1);
Texture button2 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton2.png"), false, GL11.GL_NEAREST);
GUI.AddButton(460, 214, button2.getImageWidth(), button2.getImageHeight(), button2);
Texture button3 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton3.png"), false, GL11.GL_NEAREST);
GUI.AddButton(460, 274, button3.getImageWidth(), button3.getImageHeight(), button3);
Texture button4 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton4.png"), false, GL11.GL_NEAREST);
GUI.AddButton(460, 334, button4.getImageWidth(), button4.getImageHeight(), button4);
Texture button5 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/Back.png"), false, GL11.GL_NEAREST);
GUI.AddButton(460, 394, button5.getImageWidth(), button5.getImageHeight(), button5);
BackGroundImage = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Menus/HMMenu.png"), false, GL11.GL_NEAREST);
HeightMap1 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/images/Heightmap1.png"));
HeightMap2 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/images/Heightmap2.png"));
HeightMap3 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/images/Heightmap3.png"));
} catch (IOException e) {
System.out.println("ERROR: Failed to load image @ Menu");
e.printStackTrace();
}
}
示例6: loadTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
private static int loadTexture(String fileName, boolean flipped)
{
String[] splitArray = fileName.split("\\.");
String ext = splitArray[splitArray.length - 1];
try
{
return TextureLoader.getTexture(ext, new FileInputStream(new File("./res/textures/" + fileName)), flipped, GL_NEAREST).getTextureID();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
return 0;
}
示例7: load
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
@Override
public void load() {
if (img != null) {
id = TextureUtil.loadTexture(img);
} else {
String[] splitArray = location.getPath().split("\\.");
String extension = splitArray[splitArray.length - 1];
try {
InputStream is = getLocation().getUrl().openStream();
id = TextureLoader.getTexture(extension, is).getTextureID();
} catch (Exception e) {
e.printStackTrace();
new KatamaException("Could not load texture: " + location).printStackTrace();
System.exit(1);
}
}
}
示例8: load
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
@Override
public void load() {
if(texture != null) {
texture.release();
}
if(texfile == null || !texfile.canRead()) {
log.log(Level.SEVERE, BAD_TEX_FILE);
return;
}
String filename = texfile.getName();
try {
texture = TextureLoader.getTexture(filename.substring(filename.lastIndexOf('.')), new FileInputStream(texfile));
} catch (IOException ex) {
//this should never happen probably
log.log(Level.SEVERE, null, ex);
}
createTexCoords();
}
示例9: drawBackGround
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public static void drawBackGround(){
initGL(Display.getWidth(),Display.getHeight());
try {
Texture background = TextureLoader.getTexture("JPG", ResourceLoader.getResourceAsStream("imgs/Map_test_1.jpg"));
background.bind();
glBegin(GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(1,0);
GL11.glVertex2f(background.getTextureWidth(),0);
GL11.glTexCoord2f(1,1);
GL11.glVertex2f(background.getTextureWidth(),background.getTextureHeight());
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(0,background.getTextureHeight());
GL11.glBindTexture(GL_TEXTURE_2D,0);
glEnd();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例10: drawSprites
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public static void drawSprites(String spriteLoc) {
initGL(Display.getWidth(),Display.getHeight());
try {
Texture sprite = TextureLoader.getTexture("JPG", ResourceLoader.getResourceAsStream("imgs/"+spriteLoc));
sprite.bind();
glBegin(GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(1,0);
GL11.glVertex2f(sprite.getTextureWidth(),0);
GL11.glTexCoord2f(1,1);
GL11.glVertex2f(sprite.getTextureWidth(),sprite.getTextureHeight());
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(0,sprite.getTextureHeight());
GL11.glBindTexture(GL_TEXTURE_2D,0);
glEnd();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例11: GUI_Console
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public GUI_Console(int startX, int startY, int width, int height,
String fontName, TileMap t, Player p) {
ScreenX = startX;
ScreenY = startY;
ScreenButtonWidth = width;
ScreenButtonHeight = height;
player = p;
map = t;
try {
texture = TextureLoader.getTexture("PNG", ResourceLoader
.getResourceAsStream("res/Materials/GUI/UI/Console.png"));
} catch (IOException e) {
e.printStackTrace();
}
font = LoadFont(fontName);
CharacterWidth = width / 15;
LineHeight = height / 19;
}
示例12: loadTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
private void loadTexture()
{
Pattern regex = Pattern.compile("(\\..+)");
Matcher match = regex.matcher(filePath);
match.find();
String extension = match.group();
try
{
texture = TextureLoader.getTexture(extension, ResourceLoader.getResourceAsStream(filePath));
}
catch (IOException e)
{
System.out.println("Failed to load texture at: " + filePath);
e.printStackTrace();
}
glBindTexture(GL_TEXTURE_2D, this.getTextureID());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
}
示例13: setTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
public void setTexture( String filename ) {
//public void setTexture( URL filename ) {
try {
// load texture from PNG file
//texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(filename));
//ResourceLoader.addResourceLocation( new ClasspathLocation() );// this should probably be a 1x thing
//texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream( filename.getPath() ) );
//texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream( filename.getFile() ) );
//texture = TextureLoader.getTexture("PNG", filename.openStream() );
texture = TextureLoader.getTexture("PNG", Thread.currentThread().getContextClassLoader().getResourceAsStream( filename ) );
/*System.out.println("Texture loaded: "+texture);
System.out.println(">> Image width: "+texture.getImageWidth());
System.out.println(">> Image height: "+texture.getImageHeight());
System.out.println(">> Texture width: "+texture.getTextureWidth());
System.out.println(">> Texture height: "+texture.getTextureHeight());
System.out.println(">> Texture ID: "+texture.getTextureID());*/
} catch (IOException e) {
System.out.println( "Error loading texture: " + filename );
e.printStackTrace();
}
}
示例14: init
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
@Override
public void init(GameContainer container, StateBasedGame game)
throws SlickException {
this.game = game;
imageFolder = new File("assets/memorytest");
displayImage = new Image(20,20);
displayImage2 = new Image(20,20);
fileNames = imageFolder.listFiles();
try {
tempTexture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(fileNames[fileCounter].getPath()));
displayTexture = tempTexture;
displayImage.setTexture(displayTexture);
tempTexture2 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(fileNames[fileCounter2].getPath()));
displayTexture2 = tempTexture2;
displayImage2.setTexture(displayTexture2);
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: loadTexture
import org.newdawn.slick.opengl.TextureLoader; //導入依賴的package包/類
/**
* Loads a texture from file, under resources/assets/ folder type / file name.png
* @param fileName - Name of the texture
* @param folderType - Used to find the texture since it's organized.
* @return - TextureID used for program
*/
public int loadTexture(String fileName, int folderType) {
Texture texture = null;
String folderName = "textures";
if(folderType == Reference.LOADER_MAPS_FOLDER) folderName = "maps";
if(folderType == Reference.LOADER_NORMALS_FOLDER) folderName = "normals";
if(folderType == Reference.LOADER_FONTS_FOLDER) folderName = "fonts";
if(folderType == Reference.LOADER_PARTICLES_FOLDER) folderName = "particles";
if(folderType == Reference.LOADER_SPECULARS_FOLDER) folderName = "speculars";
try {
texture = TextureLoader.getTexture("PNG", Class.class.getResourceAsStream("/assets/" + folderName + "/" + fileName + ".png"));
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0);
if(GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
float amount = Math.min(4f, GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT));
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, amount);
} else {
System.err.println("Anisotropic filtering not supported.");
}
} catch (IOException e) {
System.err.println("Failed to load texture: " + "/assets/" + folderName + "/" + fileName + ".png");
}
int textureID = texture.getTextureID();
textures.add(textureID);
return textureID;
}