OpenGL 1.1 코드를 OpenGL 2.0으로 변환하고 싶습니다.OpenGL 1.1 코드를 OpenGL 2.0으로 변환
나는 당신이 당신의 프로그램으로 쉐이더를 얻어야적인 Cocos2D 2.0 (2D 게임을 구축하기위한 프레임 워크)
OpenGL 1.1 코드를 OpenGL 2.0으로 변환하고 싶습니다.OpenGL 1.1 코드를 OpenGL 2.0으로 변환
나는 당신이 당신의 프로그램으로 쉐이더를 얻어야적인 Cocos2D 2.0 (2D 게임을 구축하기위한 프레임 워크)
먼저 사용합니다. 아래에 보여 주듯이 쉐이더 코드를 const char *에 똑같이 복사하거나 파일에서 런타임에 쉐이더를로드 할 수 있습니다.이 파일은 당신이 개발하고있는 플랫폼에 따라 다르므로 그렇게하는 방법을 보여주지 않을 것입니다.
const char *vertexShader = "... Vertex Shader source ...";
const char *fragmentShader = "... Fragment Shader source ...";
자신의 아이디의 버텍스 쉐이더와 픽셀 쉐이더 모두 쉐이더를 생성 및 저장 :
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
방금 데이터 당신이 중 하나를 사용하여 만든 쉐이더를 채울 곳은 const를 붙여 넣을 복사입니다 숯불 * 또는 파일에서로드 :
:glShaderSource(vertexShader, 1, &vertexShader, NULL);
glShaderSource(fragmentShader, 1, &fragmentShader, NULL);
그런 다음 당신에게 쉐이더를 컴파일 할 수있는 프로그램을 말할
shaderProgram = glCreateProgram();
쉐이더 프로그램으로 쉐이더를 첨부 :
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
링크 프로그램에 대한 쉐이더 프로그램
glCompileShader(vertexShader);
glCompileShader(fragmentShader);
0는 OpenGL에서 쉐이더에 대한 인터페이스는 셰이더 프로그램을 만들기 :
glLinkProgram(shaderProgram);
작성한 셰이더 프로그램을 사용하고 싶습니다.
glUseProgram(shaderProgram);
버텍스 쉐이더 :
attribute vec4 a_Position; // Attribute is data send with each vertex. Position
attribute vec2 a_TexCoord; // and texture coordinates is the example here
uniform mat4 u_ModelViewProjMatrix; // This is sent from within your program
varying mediump vec2 v_TexCoord; // varying means it is passed to next shader
void main()
{
// Multiply the model view projection matrix with the vertex position
gl_Position = u_ModelViewProjMatrix* a_Position;
v_TexCoord = a_TexCoord; // Send texture coordinate data to fragment shader.
}
조각 셰이더 :
precision mediump float; // Mandatory OpenGL ES float precision
varying vec2 v_TexCoord; // Sent in from Vertex Shader
uniform sampler2D u_Texture; // The texture to use sent from within your program.
void main()
{
// The pixel colors are set to the texture according to texture coordinates.
gl_FragColor = texture2D(u_Texture, v_TexCoord);
}
당신은 뭔가를 드로우 쉐이더를 결합해야합니다. 셰이더가 없으면 아무것도 쓸모가 없습니다. –