2016-06-27 17 views
2

私は描画OpenGLでPOINT_SIZEを見ていましたが、今はProcessingでPOINT_SIZEを取得するために定数にアクセスする方法がわかりました。GLSLを使用してProcessing 2.2.1でglPointSizeを設定するにはどうすればよいですか?

pgl.enable(PGL.ALIASED_POINT_SIZE_RANGE); 

が、私はこのエラーを得た:

OpenGL error 1280 at top endDraw(): invalid enumerant 

単にからLowLevelGL例を変更している私が試したすぐに私はそうのようなALIASED_POINT_SIZE_RANGEを有効にしようとしたProcessing javadocsをスキミングした後

例>デモ>グラフィックス:

// 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(); 
} 

ve rt.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シェーダからでサイズを変更するでしょう何ですか? GL_POINT_SIZE_RANGEGL_POINT_SIZE_GRANULARITYがGLのバージョン1.2およびそれ以上に廃止されましたので、

+0

私はProcessingについて何も知らないので、本当にあなたの質問に答えることはできません。しかし、私は 'ALIASED_POINT_SIZE_RANGE'が有効になっていないと確信しています。それは照会する価値です。エイリアス化されたポイントの有効サイズの範囲がどのようなものかをコンテキストに問い合せる方法です。 –

+0

あなたはクライアント側またはgpu側でアクセスする方法を尋ねていますか? – Nox

+0

@ TheRealNox私はクライアント側でトンを有効にしてからgpu側で使用する必要があると思いますか?これを両側で使う方法を知っていることは素晴らしいことでしょう。 (あなたが正しい方向に私を指すことができるなら、それは助けになるでしょう) –

答えて

2

はあなたの文脈のあなたのOpenGLのバージョンを確認してください。それらの機能はGL_SMOOTH_POINT_SIZE_RANGEGL_SMOOTH_POINT_SIZE_GRANULARITYに置き換えられました。

+0

それを行う最も簡単な方法は何ですか? 私はこれをやってみました: '' 'println(pgl.VERSION、pgl.SHADING_LANGUAGE_VERSION);' '' '' 7938 35724'''を表示します。私はまだOpenGL n00bですので、その部分は混乱の一部ですが、OpenGLのドキュメント(C++ API)からJOGLから処理[PJOGL](http://processing.github.io/processing -javadocs/core/processing/opengl/PJOGL.html)は、Processingを介して元のOpenGLドキュメントを見つける機能を使用します。たとえば、どのクラスが '' GL_POINT_SIZE_RANGE''定数を持つのかわかりません。 –

+0

私はよくわかりませんが、 'pgl.VERSION'はOpenGLのバージョンではなくライブラリのバージョンを与えるかもしれません。私はちょうどgithubでPGLのソースを見て、 'boolean isES()'と 'int [] getGLVersion()'のような便利な関数を見つけました。また、機能を有効にするには 'glEnable(GL_PROGRAM_POINT_SIZE);'を使う必要があります。 – Mozfox

+0

トリッキーな部分は '' 'GL_PROGRAM_POINT_SIZE'''定数が見つからず、' 'isES()' '' 'と' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'それを見て時間をとるための方法+1 @ –

関連する問題