Jump to content

  • Log In with Google      Sign In   
  • Create Account


Shawn619

Member Since 17 Mar 2012
Offline Last Active May 06 2014 11:51 AM
-----

Topics I've Started

VAO data not being received by shader

29 April 2014 - 05:59 AM

VAO data not being received by shader is only my suspicion because i don't know what's the problem.

 

I'm simply trying to pass position and color vertex attributes to the shader.

 

Global vars:

GLuint vao[3];
GLuint vertexLoc, colorLoc;
float vertices1[] = {   -3.0f, 0.0f, -5.0f, 1.0f,
            -1.0f, 0.0f, -5.0f, 1.0f,
            -2.0f, 2.0f, -5.0f, 1.0f};
float colors1[] = { 0.0f, 0.0f, 1.0f, 1.0f,
            0.0f, 1.0f, 0.0f, 1.0f,
            1.0f,0.0f, 0.0f, 1.0f};

Init:

void initRendering() {
 
std::string vertexInputString="textureVS.txt";
std::string fragmentInputString="textureFS.txt";
 
//create new shader
InitializeProgram(shaderOne, readFiletoString(vertexInputString), readFiletoString(fragmentInputString));
 
    GLuint buffers[2];
    glGenVertexArrays(3, vao);
    //
    // VAO for first triangle
    //
    glBindVertexArray(vao[0]);
    // Generate two slots for the vertex and color buffers
    glGenBuffers(1, buffers);
    // bind buffer for vertices and copy data into buffer
    glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, GL_STATIC_DRAW);
    glEnableVertexAttribArray(vertexLoc);
    glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0);
 
// bind buffer for colors and copy data into buffer
    glBindBuffer(GL_ARRAY_BUFFER, buffers[1]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(colors1), colors1, GL_STATIC_DRAW);
    glEnableVertexAttribArray(colorLoc);
    glVertexAttribPointer(colorLoc, 4, GL_FLOAT, 0, 0, 0);
 
//enables/disables
glEnable(GL_DEPTH_TEST);
glEnable (GL_BLEND);
 
//load textures
image = SOIL_load_OGL_texture(
        "resources/blank.png",
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID,
        SOIL_FLAG_INVERT_Y
    );
if( 0 == image ){printf( "SOIL loading error: '%s'\n", SOIL_last_result());}
 
//start shader
glUseProgram(shaderOne);
 
 
vertexLoc = glGetAttribLocation(shaderOne,"position");
colorLoc = glGetAttribLocation(shaderOne,"color");
 
}

Draw:

void drawPerspectiveScene(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, windowWidth, windowHeight);
glClearColor(0.5,5.5,0.25,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (float)windowWidth / (float)windowHeight, 0.4, 9000.0);
glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
 
//set camera
gluLookAt(cam.posX,cam.posY,cam.posZ,cam.viewX,cam.viewY,cam.viewZ,cam.upX,cam.upY,cam.upZ);
 
glColor3f(0.0,0.0,1.0);
 
glBindVertexArray(vao[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
 

//swap buffers
glutPostRedisplay();
glutSwapBuffers();
 
}

GLSL:

 

Vert:

attribute vec4 position;
attribute vec4 color;
varying vec4 Color;
 
void main() {
Color=color; 
gl_Position = gl_ModelViewProjectionMatrix * position;
}

Frag:

varying vec4 color;
 
void main()
{
    gl_FragColor = color;
}
 

I know im using deprecated function, this is my first step towards modern opengl.

 

It renders without error, however it uses the color data as vertex position data, so the triangle looks distorted.


OpenGL - glGenVertexArrays() and glBindVertexArray() identifier not found

28 April 2014 - 12:50 AM

I'm trying to run a piece of code from Lighthouse, but OpenGL can't even locate the functions in order to run the code.

 

I have a glewInit() and such enabled:

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(windowWidth, windowHeight);
 
glutCreateWindow("VAO");
glewInit();
initRendering();
glutWarpPointer(windowWidth/2, windowHeight/2);
glutDisplayFunc(drawPerspectiveScene);
glutMouseFunc(mouseClicked);
glutMotionFunc(mouseClickedActive);
glutPassiveMotionFunc(mouseMovement);
glutKeyboardFunc(handleKeypress);
glutKeyboardUpFunc(handleKeypressUp);
glutReshapeFunc(handleResize);
 
glutMainLoop();
return 0;
}

Errors:

main.cpp(286): error C3861: 'glGenVertexArrays': identifier not found
main.cpp(290): error C3861: 'glBindVertexArray': identifier not found
main.cpp(503): error C3861: 'glBindVertexArray': identifier not found

A piece of code using the functions:

    GLuint buffers;
    glGenVertexArrays(3, vao);
    //
    // VAO for first triangle
    //
    glBindVertexArray(vao[0]);
    // Generate two slots for the vertex and color buffers
    glGenBuffers(1, buffers);
    // bind buffer for vertices and copy data into buffer
    glBindBuffer(GL_ARRAY_BUFFER, buffers);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, GL_STATIC_DRAW);
    glEnableVertexAttribArray(vertexLoc);
    glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0);

Alpha blending with a color that has no RGB components

27 April 2014 - 05:13 AM

I'm curious what the RGB components are of the alpha part of a PNG texture when it comes to alpha blending.

 

Given a PNG texture that is completely transparent with no color parts acting as the destination, and a red color {1.0,0.0,0.0,1.0} acting as the source in the glBlendFunc(GL_SRC_ALPHA, GL_ONE) equation:

 

Final color = (source color*source factor)+(destination color*destination factor)

= ({1.0,0.0,0.0,1.0}*1.0) + ({?,?,?,0.0}*{1.0,1.0,1.0,1.0})

 

I have no idea what OpenGL uses as the RGB component for a fully transparent texture in order to complete the equation.


gluLookAt() and matrix stack operations deprecated?

26 April 2014 - 05:02 AM

I have a couple question about some opengl deprecated functionality and it's replacements:

 

1.) I'm told gluLookAt() is deprecated in 3.0. What do i use as it's replacement? Do i multiply a camera rotation matrix by the view matrix to get the new view matrix?

 

2.) My understanding was that OpenGL works with a 32 stack of 4x4 ModelView matrices. If i can't push and pop matrices anymore and vertex data is in a VAO, then there is absolutely no point in 32 stacks and it mine as well be 1 ModelView matrix?


OpenGL - Soil texture all black

24 April 2014 - 06:57 PM

I've never seen anyone on google searches with this problem so i came here.

I linked, included, and did everything necessary to use SOIL and it's functions.

I load the texture like so in init():

void initRendering() {



std::string vertexInputString="exampleVS.txt";

std::string fragmentInputString="exampleFS.txt";



//create new shader

InitializeProgram(shaderOne, readFiletoString(vertexInputString), readFiletoString(fragmentInputString));



//enables/disables

glEnable(GL_DEPTH_TEST);

glEnable(GL_TEXTURE_2D);

glEnable (GL_BLEND);

//glEnable(GL_LIGHTING);

//glEnable(GL_LIGHT0);



//states

glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);



//load textures

image = SOIL_load_OGL_texture(

"resources/wood.png",

SOIL_LOAD_AUTO,

SOIL_CREATE_NEW_ID,

SOIL_FLAG_INVERT_Y

);

if( 0 == image ){printf( "SOIL loading error: '%s'\n", SOIL_last_result());}





//start shader

glUseProgram(shaderOne);

}

For simplicity the wood.png is a 256x256 png texture and loads without an error message.

Here is where i draw the textured quad:

glPushMatrix();

glColor4f(0.0, 0.0, 0.0,1.0f);

glBindTexture(GL_TEXTURE_2D, image);

//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);

//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // when texture area is small, bilinear filter the closest mipmap

//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // when texture area is large, bilinear filter the first mipmap

//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // texture should tile

//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);



glNormal3f(0.0, 1.0f, 0.0f);



glTexCoord2f(0.0f,0.0f); glVertex3f(-50.0f, 10.0f, 50.0f);

glTexCoord2f(0.0f,1.0f); glVertex3f(-50.0f, 10.0f, -50.0f);

glTexCoord2f(1.0f,1.0f); glVertex3f(50.0f, 10.0f, -50.0f);

glTexCoord2f(1.0f,0.0f); glVertex3f(50.0f, 10.0f, 50.0f);



glEnd();



glPopMatrix();

The result is simply an all black texture instead of a wood texture:

lkSFV.png

atyH0.png


PARTNERS