- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试画一条线 LWJGL 3。我可以在 render()
方法中更改框的背景颜色,但无法画线。
代码如下:
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.opencl.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
public class Main {
// The window handle
private long window;
enum GameState {
MAIN, GAME, PAUSED;
}
GameState state;
GLFWKeyCallback keyCallback;
Box box;
public void run() {
try {
init();
loop();
}catch(Exception e) {
e.printStackTrace();
}
}
private void init() {
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
int WIDTH = 300;
int HEIGHT = 300;
window = glfwCreateWindow(WIDTH, HEIGHT, "Hello World!", NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
glfwSetKeyCallback(window, keyCallback = new Input());
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(
window,
(vidmode.width() - WIDTH) / 2,
(vidmode.height() - HEIGHT) / 2
);
glfwMakeContextCurrent(window);
glfwShowWindow(window);
state = GameState.MAIN;
box = new Box(100, 100, 10, 10, 10);
}
private void loop() {
GL.createCapabilities();
// Set the clear color
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while ( !glfwWindowShouldClose(window) ) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
render();
update();
updateKeys();
}
}
void update() {
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
switch(state){
case MAIN:
break;
case GAME:
break;
}
}
void updateKeys() {
switch(state) {
case MAIN:
if(Input.keys[GLFW_KEY_SPACE]) { state = GameState.GAME; }
break;
case GAME:
if(Input.keys[GLFW_KEY_UP]) {
}
break;
default:
break;
}
}
void render() {
glfwSwapBuffers(window); // swap the color buffers
switch(state) {
case MAIN:
break;
case GAME:
System.out.println("game rendering");
box.render();
break;
}
}
public static void main(String[] args) {
new Main().run();
}
class Box {
int x, y;
int dx, dy;
float speed;
float r, g, b;
boolean up, down, left, right;
void setUp(boolean b) { up = b; }
void setDown(boolean b) { down = b; }
void setLeft(boolean b) { left = b; }
void setRight(boolean b) { right = b; }
Box(int x, int y, float r, float g, float b) {
this.x = x;
this.y = y;
dx = 0;
dy = 0;
speed = 5;
this.r = r;
this.g = g;
this.b = b;
}
void update() {
if(up)
y += (int) speed;
if(down)
y += (int) -speed;
if(left)
x = (int) -speed;
if(right)
x = (int) speed;
x += dx;
y += dy;
dx = 0;
dy = 0;
}
void render() {
glColor3f(1, 1, 1);
glBegin(GL_LINES);
glVertex2f(10, 10);
glVertex2f(20, 20);
glEnd();
}
}
static class Input extends GLFWKeyCallback {
public static boolean[] keys = new boolean[65535];
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
keys[key] = action != GLFW_RELEASE;
}
}
}
最佳答案
你需要用 glPushMatrix() 和 glPopMatrix() 包围你的渲染方法,我相当确定
关于java - LWJGL 中未绘制线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38192621/
如何以编程方式创建最大化的 lwjgl 窗口或使已创建的显示最大化? 注意:我不是问如何为显示器设置全屏模式。 最佳答案 Display.setResizable(true) 这将启用最大化按钮。 关
我对使用外部 Java 库非常陌生,我从基于 LWJGL 构建的 Slick2D 开始。我编写了一个简单的 StateBasedGame,它只在屏幕上打印三个选项。它给了我一个关于某些(jar?)文件
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr ary.path at
我正在 Itellij 中制作一个依赖 org.lwjgl.input 代码的 Minecraft mod。该库已从 LWJGL 3 中删除,因此我必须使用 LWJGL 2。我将正确的 LWJGL 2
我安装了 lwjgl 库和 natives 并将其放入/lib 文件夹。在 Eclipse Java 构建路径上设置库位置和 native 库位置。当我尝试在 Eclipse 上运行它时,它可以工作,
所以我已经使用 LWJGL 开发一个程序很长一段时间了,现在我希望能够轻松地向其他人展示它。但是,当我尝试将其导出为可运行的 jar 文件并在控制台中运行时,出现上述错误。 我还尝试将其导出为普通的
我尝试使用 LWJGL 编译 ( NetBeans ) Java 项目。我单击了项目 -> 属性,然后单击库 -> 编译。我添加了 Jars 位置、源文件位置和 javadoc 位置。 当我尝试构建项
在 NEHE 第 06 课 (http://nehe.gamedev.net/tutorial/texture_mapping/12038/) 中,您可以加载图像并用它来纹理对象。我目前使用的是LWJ
我正在尝试向我的程序添加全屏功能,但我无法让它工作。我想 Display.setFullscreen(true); 我尝试将其位置更改为创建显示的位置或设置显示模式的位置上方,但仍然无法正常工作。有什
我刚刚开始使用 LWJGL 和 OpenGL,但遇到了问题。我正在尝试弄清楚如何使用我找到的游戏引擎为我正在制作的游戏绘制一条简单的线条。 这是我正在使用的引擎的链接:https://github.c
我正在尝试在 java lwjgl 2.9 中编译着色器,如果我运行我的游戏,它无法编译着色器。问题是为什么着色器不重新识别 const 关键字,如果我删除 const 那么它会抛出错误 float
我在使用 Java 和 lwjgl 导入时遇到问题: import org.lwjgl.input.Keyboard; 行不通。我已经添加了 jar : lwjgl-glfw.jar lwjgl-op
我在 OpenGL 上下文中移动实体时遇到问题:当我尝试放置一个实体时,位置似乎是正确的,但是当实体开始移动时,一切都会出错,并且碰撞不起作用。我是 OpenGL 新手,我怀疑我的世界矩阵或模型矩阵是
我正在做一项家庭作业,使用 LightWeight Java 游戏库修改教授给出的代码。问题是我无法完全加载测试代码来开始测试修改。我已经按照修改中的说明链接了 jar 文件,但仍然存在一个挥之不去的
我是 Java 新手,我想将基本的 LWJGL 小程序上传到我的网站并在浏览器中播放。我不知道该怎么做,我想确保在继续开发游戏之前我知道如何让它工作。请帮助我,因为我不知道如何将 JWJGL 小程序或
我正在尝试旋转屏幕上的两个对象之一。我该怎么做?我只能让它旋转屏幕上的所有对象。代码: glColor3f(1, 0, 0); glBegin(GL_QUADS
我目前正在渲染一个天空盒,如下所示: //Front Face GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[0].getText
我正在编写类似 Minecraft 的游戏。为了加载纹理和字体(目前没有声音),我使用 slick。 Slick 不再开发,maven 存储库不可用。是否有其他库(LibGDX 除外)可用于加载 lw
我正在尝试使用opengl在lwjgl显示屏上显示具有自定义字体的文本。目前,我正在使用自定义位图字体类从png文件加载字体,并以与tileet相同的方式显示它们。它可以正常工作,但是当我将文本绘制到
我正在使用 VBO 来渲染游戏中的所有立方体(因为会有很多立方体),并且我希望它们都带有纹理。当我运行我的代码时,立方体没有纹理(相反,它看起来有点红色,因为我的纹理是砖墙),并且只有当我非常接近立方
我是一名优秀的程序员,十分优秀!