本文整理匯總了Java中org.lwjgl.opengl.GL30.glGenerateMipmap方法的典型用法代碼示例。如果您正苦於以下問題:Java GL30.glGenerateMipmap方法的具體用法?Java GL30.glGenerateMipmap怎麽用?Java GL30.glGenerateMipmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.lwjgl.opengl.GL30
的用法示例。
在下文中一共展示了GL30.glGenerateMipmap方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTexture
import org.lwjgl.opengl.GL30; //導入方法依賴的package包/類
/**
* Creates an OpenGL texture based on a given Image
* @param id OpenGL reference id to create texture in
* @param image
*/
private void createTexture(int id, Image image) {
// Set as texture 0
GL13.glActiveTexture(GL13.GL_TEXTURE0);
bind();
// Set pixel storage mode
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
// Setup texture
GL11.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.buffer);
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
unbind();
}
示例2: genCompositeMipmap
import org.lwjgl.opengl.GL30; //導入方法依賴的package包/類
public static void genCompositeMipmap()
{
if (hasGlGenMipmap)
{
for (int i = 0; i < usedColorBuffers; ++i)
{
if ((activeCompositeMipmapSetting & 1 << i) != 0)
{
GlStateManager.setActiveTexture(33984 + colorTextureTextureImageUnit[i]);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL30.glGenerateMipmap(3553);
}
}
GlStateManager.setActiveTexture(33984);
}
}
示例3: loadTexture
import org.lwjgl.opengl.GL30; //導入方法依賴的package包/類
public static Texture loadTexture(String textureFile) {
try {
// InputStream in = TextureLoader.class.getResourceAsStream("/" + textureFile);
InputStream in = Util.loadInternal(textureFile);
BufferedImage image = ImageIO.read(in);
int[] pixels = new int[image.getWidth() * image.getHeight()];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
ByteBuffer buffer = ByteBuffer.allocateDirect(image.getWidth() * image.getHeight() * 4);
for(int h = 0; h < image.getHeight(); h++) {
for(int w = 0; w < image.getWidth(); w++) {
int pixel = pixels[h * image.getWidth() + w];
buffer.put((byte) ((pixel >> 16) & 0xFF));
buffer.put((byte) ((pixel >> 8) & 0xFF));
buffer.put((byte) (pixel & 0xFF));
buffer.put((byte) ((pixel >> 24) & 0xFF));
}
}
buffer.flip();
in.close();
int textureID = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_MAX_TEXTURE_LOD_BIAS, -1);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
return new Texture(textureID, image.getWidth(), image.getHeight());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例4: loadTextureToOpenGL
import org.lwjgl.opengl.GL30; //導入方法依賴的package包/類
protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) {
int texID = GL11.glGenTextures();
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA,
GL11.GL_UNSIGNED_BYTE, data.getBuffer());
if (builder.isMipmap()) {
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
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_MIPMAP_LINEAR);
if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
4.0f);
}
} else if (builder.isNearest()) {
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
} else {
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);
}
if (builder.isClampEdges()) {
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);
} else {
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);
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
return texID;
}
示例5: bindTexture
import org.lwjgl.opengl.GL30; //導入方法依賴的package包/類
static int bindTexture(ResourceLocation location) {
ChessMaster.getLogger().info("Binding texture " + location);
int textureId = glGenTextures();
URL imageURL = null;
if (location.getDomain().equals("chessmaster"))
imageURL = ChessMaster.class.getResource("assets/chessmaster/textures/" + location.getLocation());
else {
PluginWrapper wrapper = ChessMaster.getPluginManager().getPlugin(location.getDomain());
if (wrapper == null)
ChessMaster.getLogger().error("No such plugin called " + location.getDomain(), new NullPointerException());
else
imageURL = wrapper.getPluginClassLoader().getResource("assets/" + location.getDomain() + "/textures/" + location.getLocation());
}
try {
//noinspection ConstantConditions
BufferedImage image = ImageIO.read(imageURL);
ChessMaster.getLogger().info("Readed image " + image);
int[] pixels = new int[image.getWidth() * image.getHeight()];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4); //4 for RGBA, 3 for RGB
for(int y = 0; y < image.getHeight(); y++){
for(int x = 0; x < image.getWidth(); x++){
int pixel = pixels[y * image.getWidth() + x];
buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component
buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
buffer.put((byte) (pixel & 0xFF)); // Blue component
buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA
}
}
buffer.flip();
ChessMaster.getLogger().info("Create buffer of " + imageURL + " : " + buffer);
GL13.glActiveTexture(textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//Setup wrap mode
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
//Setup texture scaling filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
GL30.glGenerateMipmap(GL_TEXTURE_2D);
} catch (Exception e) {
ChessMaster.getLogger().error("Cannot bind texture " + location, e);
}
OpenGLRenderer.getResourceTextureIdMap().put(location, textureId);
return textureId;
}
示例6: renderEnvironmentMap
import org.lwjgl.opengl.GL30; //導入方法依賴的package包/類
public static void renderEnvironmentMap(Texture cubeMap, Scene scene, Vector3f center, MasterRenderer renderer) {
CubeMapCamera camera = new CubeMapCamera(center);
//create fbo
int fbo = GL30.glGenFramebuffers();
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);
//attach depth buffer
int depthBuffer = GL30.glGenRenderbuffers();
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, cubeMap.size, cubeMap.size);
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
depthBuffer);
//indicate that we want to render to the entire face
GL11.glViewport(0, 0, cubeMap.size, cubeMap.size);
//loop faces
for (int i = 0; i < 6; i++) {
//attach face to fbo as color attachment 0
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0,
GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubeMap.textureId, 0);
//point camera in the right direction
camera.switchToFace(i);
//render scene to fbo, and therefore to the current face of the cubemap
renderer.renderLowQualityScene(scene, camera);
}
//stop rendering to fbo
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
//delete fbo
GL30.glDeleteRenderbuffers(depthBuffer);
GL30.glDeleteFramebuffers(fbo);
cubeMap.bindToUnit(0);
GL30.glGenerateMipmap(GL13.GL_TEXTURE_CUBE_MAP);
}
示例7: Texture
import org.lwjgl.opengl.GL30; //導入方法依賴的package包/類
public Texture(String path){
this.path = path;
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
IntBuffer c = BufferUtils.createIntBuffer(1);
ByteBuffer data = ResourceLoader.getBytes(path);
if(stbi_info_from_memory(data, w, h, c) != 1)
Application.error("Unable to load:" + path);
ByteBuffer formatted = stbi_load_from_memory(data, w, h, c, 0);
if(formatted == null)
Application.error("Unable to format file: " + path);
width = w.get(0);
height = h.get(0);
comp = c.get(0);
size = new Vector2f(width, height);
//load texture
id = glGenTextures();
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, formatted);
GL30.glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(formatted);
formatted.clear();
data.clear();
w.clear();
h.clear();
c.clear();
textures.add(this);
}