English 中文(简体)
LWJGL 3angle w 开放式投票
原标题:Basic LWJGL triangle w/ OpenGL

I m试图利用LWJGL在贾瓦获得一个简单的三角。

我试图获得一个简单的三角,每个角落都有一个具体肤色。 现在,这只是给我一个空白的屏幕。

我的守则是:

package com.ex;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.input.Keyboard;

public class ColoredTriangle {
    public void start() {
        try {
            Display.setDisplayMode(new DisplayMode(640, 480));
            Display.create();
        } catch (LWJGLException e) {
            e.printStackTrace();
            System.exit(0);
        }

        // Init OpenGL
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, 640, 480, 0, 1, -1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);

        boolean quit = false;

        while (!quit) {         
            // Clear the screen.
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

            // Begin drawing
            GL11.glBegin(GL11.GL_TRIANGLES);
                // Top & Red
                GL11.glColor3f(1.0f, 0.0f, 0.0f);
                GL11.glVertex2f(0.0f, 1.0f);

                // Right & Green
                GL11.glColor3f(0.0f, 1.0f, 0.0f);
                GL11.glVertex2f(1.0f, 1.0f);

                // Left & Blue
                GL11.glColor3f(0.0f, 0.0f, 1.0f);
                GL11.glVertex2f(1.0f, -1.0f);
            GL11.glEnd();

            Display.update();

            if (Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
                quit = true;
        }

        Display.destroy();
    }

    public static void main(String args[]) {
        ColoredTriangle ct = new ColoredTriangle();
        ct.start();
    }

}
最佳回答

这完全是轻重的,只是你三角地高1个单位,你的窗户高480个单位,因此它只显示在玉米的一台钢板。

请替换GL11.glOrtho(0,640,480, 0, 1, -1); with GL11.glOrtho(-3.2, 3.2, -2.4, 2.4, -1, 1);, 然后请看一切照样。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签