Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OpenGL通用错误1282,发布图形GL\U四边形_Java_Opengl_Lwjgl - Fatal编程技术网

Java OpenGL通用错误1282,发布图形GL\U四边形

Java OpenGL通用错误1282,发布图形GL\U四边形,java,opengl,lwjgl,Java,Opengl,Lwjgl,我正试图用Java中的LGJWL(Java原生OpenGL绑定)绘制一个红方块。我从OpenGL收到一个1282错误,我的方块没有出现 下面是(我认为是)我尝试做的基本实现 // begin drawing quads glBegin(GL11.GL_QUADS); // set color glColor4d(255, 0, 0, 255); // draw rectangle vertices glVertex2i(0, 0); glVertex2i(100, 0); glVertex2

我正试图用Java中的LGJWL(Java原生OpenGL绑定)绘制一个红方块。我从OpenGL收到一个1282错误,我的方块没有出现

下面是(我认为是)我尝试做的基本实现

// begin drawing quads
glBegin(GL11.GL_QUADS);

// set color
glColor4d(255, 0, 0, 255);

// draw rectangle vertices
glVertex2i(0, 0);
glVertex2i(100, 0);
glVertex2i(100, 100);
glVertex2i(0, 100);

glEnd();
下面是我在实践中要做的

public class WindowComponent extends Component {
    /** Window color */
    private Color color = new Color();

    /**
     * Sets the window's color
     * @param r red
     * @param b blue
     * @param g green
     * @param a alpha
     */
    public void setColor(int r, int g, int b, int a) {
        color.set(r, g, b, a);
    }

    /**
     * @see Component#renderComponent()
     */
    @Override
    protected void renderComponent() {
        // begin drawing quads
        begin(GL11.GL_QUADS);

        // set color
        GL11.glColor4ub(color.getRedByte(), color.getGreenByte(), color.getBlueByte(), color.getAlphaByte());

        // draw rectangle vertices
        GL11.glVertex2i(0, 0);
        GL11.glVertex2i(getWidth(), 0);
        GL11.glVertex2i(getWidth(), getHeight());
        GL11.glVertex2i(0, getHeight());

        end();
    }
}
是…的延伸

public abstract class Component {
    /** Dimension of component */
    private Dimension size = new Dimension();
    /** Position of component */
    private Vector2f position = new Vector2f();

    /**
     * Gets width
     * @return width
     */
    public int getWidth() {
        return size.getWidth();
    }
    /**
     * Gets height
     * @return height
     */
    public int getHeight() {
        return size.getHeight();
    }
    /**
     * Gets size
     * @return size
     */
    public Dimension getSize() {
        return size;
    }

    /**
     * Gets X position
     * @return X position
     */
    public float getX() {
        return position.getX();
    }
    /**
     * Gets Y position
     * @return Y position
     */
    public float getY() {
        return position.getY();
    }
    /**
     * Gets position vector
     * @return position vector
     */
    public Vector2f getPosition() {
        return position;
    }

    /**
     * Sets width
     * @param width width
     */
    public void setWidth(int width) {
        size.setWidth(width);
    }
    /**
     * Sets height
     * @param height height
     */
    public void setHeight(int height) {
        size.setHeight(height);
    }
    /**
     * Sets size
     * @param width width
     * @param height height
     */
    public void setSize(int width, int height) {
        size.setSize(width, height);
    }

    /**
     * Sets X position
     * @param x X position
     */
    public void setX(float x) {
        position.setX(x);
    }

    /**
     * Sets Y position
     * @param y Y position
     */
    public void setY(float y) {
        position.setY(y);
    }

    /**
     * Sets position
     * @param x X position
     * @param y Y position
     */
    public void setPosition(float x, float y) {
        position.set(x, y);
    }

    /**
     * Begins drawing and does parent translations
     * @param mode drawing mode
     */
    protected void begin(int mode) {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glBegin(mode);
        GL11.glTranslatef(getX(), getY(), 0);
    }

    /**
     * Ends drawing and does parent translations
     */
    protected void end() {
        GL11.glTranslatef(-getX(), -getY(), 0);
        GL11.glEnd();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }

    /**
     * Applies pre-rendering checks then renders the component
     */
    public void render() {
        renderComponent();
    }

    /**
     * Component rendering code here
     */
    protected abstract void renderComponent();
}
我正在初始化这一切与

    WindowComponent window = new WindowComponent();
    window.setSize(100, 100);
    window.setPosition(100, 100);
    window.setColor(255, 0, 0, 255);
    window.render();
开始中

GL11.glBegin(mode);
GL11.glTranslatef(getX(), getY(), 0);
您不能在
glBegin
glEnd
之间调用
glTranslate
;把它移到前面