• Advertisement

Shawn619

Member
  • Content count

    153
  • Joined

  • Last visited

Community Reputation

342 Neutral

About Shawn619

  • Rank
    Member
  1. 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.
  2. Works flawless now. Words cannot express my gratitude.
  3. I was actually using an incredibly old glew.h that had x2 less lines than the current GLEW, but i used it because it was so hard for me to get GLEW linking correctly with the newest GLEW.   So i'm going to change to the newest version, but i'm having the same linking errors.   I downloaded the newest GLEW from http://glew.sourceforge.net -> Source -> Zip   I'm using the x32 GLEW version files since im using VS2010 32-bit version, and I guess you could say im trying to build the "static" GLEW version.   I haven't included any of the glew.h or other glew files into my project. //includes #define GLEW_STATIC #include <GL/glew.h> #include <GL/glut.h> ...   The necessary 32-bit include GLEW files are in their appropriate file include directory. The glew lib folder that i downloaded had a lib folder with "glew32.lib" and "glew32s.lib" so included those path into the linker path, then added those files into the appropriate linker directory.   My linkers look like this: opengl32.lib glut32.lib libSOIL.a glew32.lib glew32s.lib   My current errors: 1>------ Build started: Project: VAO, Configuration: Debug Win32 ------ 1>glew32s.lib(glew.obj) : error LNK2005: _glewInit@0 already defined in glew32.lib(glew32.dll) 1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library 1>C:\Users\Shawn\Documents\Visual Studio 2010\Projects\VAO\Debug\VAO.exe : fatal error LNK1169: one or more multiply defined symbols found ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  4. 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);
  5. Thanks for your very knowledgeable opinions, guys.   I believe that my opengl setup(SOIL+GIMP as PNG exporter) produces {1,1,1} RGB default values for color values that are unspecified.   For anyone interested in how i arrived at {1,1,1}, you can do you're own test if you're using a different texture loader and/or exporter than mine by doing the following:   Use the following blending equation, glBlendFunc(GL_DST_ALPHA, GL_SRC_ALPHA);   with an opaque source color(a color with alpha=1, ie:{0,0,1,1}) and whatever transparent texture destination for testing.   Which will simply eliminate the srccolor and leave us with the unaltered destcolor,   Final color = (srccolor*srcfactor)+(destcolor*destfactor) = (srccolor*Da)+(destcolor*Sa) = ({Sr, Sg, Sb, 1}*0)+(destcolor*1) =(0)+(destcolor) =destcolor   My opengl render left me with a white color.
  6. Yeah, i'm just wondering if anyone knows what those default values are for image loaders like SOIL and DevIL.
  7. 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.
  8. I'm understanding more, thank you guys.   I have a couple important questions that would really help me understand these model, view, and proj matrices so i can construct them myself:   (i) In response to "OandO", if i provide object space data to the buffers, like a triangle for example: float vertices1[] = {   -1.0f, 0.0f, 0.0f, 1.0f,             1.0f, 0.0f, 0.0f, 1.0f,             0.0f, 2.0f, 0.0f, 1.0f}; which is later sent to a VAO: glGenVertexArrays(3, vao);     //     // VAO for first triangle     //     glBindVertexArray(vao[0]);     // Generate two slots for the vertex and color buffers     glGenBuffers(2, 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); How would i move the triangle 5 pixels into the screen(glTranslatef(0.0,0.0,-5.0);) in non-deprecated terms? Because if i alter the "vertices1" vertices to add -5.0 in the z-component(push triangle further back), isn't that changing the vertices from object->world space?   (ii) Does a ModelViewProjection 4v4 matrix exist such that any vertex position data for any object sent into a VAO/VBO multiplied by this ModelViewProjection 4v4 will give you that vertex position in world space?   Thank you again guys.
  9. Sorry for all the questions.   Do i send eye-space vertex positions in the VAO/VBO? Because model-space vertex positions in the VAO/VBO wouldn't make sense, right? 
  10. I see, i see.   I have a couple last questions:     (i) Since i feed vertex position in eye space into the VAO/VBO, instead of model space vertex position through glBegin->glVertex3f->glEnd, does this mean, in my vertex shader, i no longer need to transform the received vertex from model->eye space like so: void main() {       gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; } and i can instead do the following since im passing in eye space vertex positions to thee vertex shader?: attribute vec4 v_coord; attribute vec3 v_normal;   void main() {       gl_Position = v_coord; } (ii) I know i have to control the MVP matrices myself, then send them to the shader. When do i change the Model matrix? Because in legacy opengl, the Model matrix was changed with every glTranslate or glRotate call.
  11. Do you have a sample program code by chance or can tell me how i could manage model, view, and proj matrix? It seems like 99% of opengl tutorial code on the web is using functionality that was deprecated years before they published the tutorial.   Could i get the MVP matrices like so, then send modelview[16] to the shader: float modelview[16]; glGetFloatv(GL_MODELVIEW_MATRIX, modelview);
  12. 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?
  13. Solved! I had my shader on when i was rending the textured quad, and since my shader doesnt support textures(yet), the color of my quad was just whatever the most recent glColor was.
  • Advertisement