我正在查看POINT_SIZE在绘制 OpenGL 中,但我现在确定如何访问常量以在处理中获取 POINT_SIZE。
快速浏览完 Processing javadocs 后我尝试启用 ALIASED_POINT_SIZE_RANGE像这样:
pgl.enable(PGL.ALIASED_POINT_SIZE_RANGE);
但是我收到了这个错误:
OpenGL error 1280 at top endDraw(): invalid enumerant
我尝试过的只是修改示例>演示>图形中的LowLevelGL示例:
// Draws a triangle using low-level OpenGL calls.
import java.nio.*;
PGL pgl;
PShader sh;
int vertLoc;
int colorLoc;
float[] vertices;
float[] colors;
FloatBuffer vertData;
FloatBuffer colorData;
void setup() {
size(640, 360, P3D);
// Loads a shader to render geometry w/out
// textures and lights.
sh = loadShader("frag.glsl", "vert.glsl");
vertices = new float[12];
vertData = allocateDirectFloatBuffer(12);
colors = new float[12];
colorData = allocateDirectFloatBuffer(12);
}
void draw() {
background(0);
// The geometric transformations will be automatically passed
// to the shader.
rotate(frameCount * 0.01, width, height, 0);
updateGeometry();
pgl = beginPGL();
sh.bind();
pgl.enable(PGL.ALIASED_POINT_SIZE_RANGE);
vertLoc = pgl.getAttribLocation(sh.glProgram, "vertex");
colorLoc = pgl.getAttribLocation(sh.glProgram, "color");
pgl.enableVertexAttribArray(vertLoc);
pgl.enableVertexAttribArray(colorLoc);
pgl.vertexAttribPointer(vertLoc, 4, PGL.FLOAT, false, 0, vertData);
pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 0, colorData);
pgl.drawArrays(PGL.TRIANGLES, 0, 3);
pgl.disableVertexAttribArray(vertLoc);
pgl.disableVertexAttribArray(colorLoc);
sh.unbind();
endPGL();
}
void updateGeometry() {
// Vertex 1
vertices[0] = 0;
vertices[1] = 0;
vertices[2] = 0;
vertices[3] = 1;
colors[0] = 1;
colors[1] = 0;
colors[2] = 0;
colors[3] = 1;
// Corner 2
vertices[4] = width/2;
vertices[5] = height;
vertices[6] = 0;
vertices[7] = 1;
colors[4] = 0;
colors[5] = 1;
colors[6] = 0;
colors[7] = 1;
// Corner 3
vertices[8] = width;
vertices[9] = 0;
vertices[10] = 0;
vertices[11] = 1;
colors[8] = 0;
colors[9] = 0;
colors[10] = 1;
colors[11] = 1;
vertData.rewind();
vertData.put(vertices);
vertData.position(0);
colorData.rewind();
colorData.put(colors);
colorData.position(0);
}
FloatBuffer allocateDirectFloatBuffer(int n) {
return ByteBuffer.allocateDirect(n * Float.SIZE/8).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
vert.glsl:
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
uniform mat4 transform;
attribute vec4 vertex;
attribute vec4 color;
varying vec4 vertColor;
void main() {
gl_PointSize = 200.0;
gl_Position = transform * vertex;
vertColor = color;
}
frag.glsl:
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
varying vec4 vertColor;
void main() {
gl_FragColor = vertColor;
}
我的问题明确是我需要访问什么处理对象才能启用 POINT_SIZE 以及如何从 GLSL 着色器更改大小?
最佳答案
尝试检查上下文的 OpenGL 版本,因为 GL_POINT_SIZE_RANGE
和 GL_POINT_SIZE_GRANULARITY
在 GL 版本 1.2 中已弃用和更大。它们的功能已被 GL_SMOOTH_POINT_SIZE_RANGE
和 GL_SMOOTH_POINT_SIZE_GRANULARITY
取代。
关于opengl - 如何使用GLSL在Processing 2.2.1中设置glPointSize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38065000/