Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: turning fixed funtion to programmable funtion

  1. #1
    Junior Member Newbie
    Join Date
    May 2014

    turning fixed function to programmable function

    I am reworking an old school project that was written to using the OpenGL fixed function pipeline code. I want to rewrite it using GLSL rather then the fixed pipeline and modernize the project. I have written the shaders but I do not want to modify my code to test if the shaders work.
    the code is:
    for (int i = 0; i < n; i++)
    I am fine using triangle fans instead of polygons because for the most part my polygon are convex and not concave. Also I am find putting the buffer data into one temp buffer while randering

    Thank in advanced
    Last edited by vickoza; 05-06-2014 at 01:30 PM. Reason: spellling correction

  2. #2
    Junior Member Newbie
    Join Date
    May 2014
    I have tried putting my vertex and normal information into array buffers but I am getting no information

    The following code is my first attempt if there is a better OpenGL 3.0+ way to do the I would also appreciate this.
    double *pointsBuff, *normlsBuff;
    pointsBuff = new double[n*3];
    normlsBuff = new double[n*3];
    for (int i = 0; i < n; i++) //loads data into the arrray
    int pos = i * 3;
    pointsBuff[pos] = (p[i])[0];
    pointsBuff[pos+1] = (p[i])[1];
    pointsBuff[pos+2] = (p[i])[2];
    normlsBuff[pos] = (vn[i])[0];
    normlsBuff[pos+1] = (vn[i])[1];
    normlsBuff[pos+2] = (vn[i])[2];
    glVertexPointer(3, GL_DOUBLE, 0, pointsBuff);
    glNormalPointer(GL_DOUBLE, 0, normlsBuff);
    glDrawArrays(GL_POLYGON, 0, n);
    delete [] pointsBuff;
    delete [] normlsBuff;

    Thank again in advanced

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Please use [code][/code] around source code snippets.

    I have written the shaders but I do not want to modify my code to test if the shaders work.
    I'm afraid that is not possible, you'll at least have to include code to generate the shader and program objects, load, compile, and link the code (for shader code this is done at runtime with OpenGL commands, not your C/C++ compiler) and activate the shader before drawing.

    I have tried putting my vertex and normal information into array buffers
    Sorry, you've put the information into plain arrays, that is completely different from putting them into OpenGL buffer objects, which is what you want to do in "modern" OpenGL. My suggestion would be to look through some of the tutorials on the wiki that should get you started on how to use buffer objects and shaders.

  4. #4
    Junior Member Newbie
    Join Date
    May 2014
    Thank not I have a new problem
    Code :
    		vbo_Data[i].gl_Vertex[0] = p[i].c[0];
    		vbo_Data[i].gl_Vertex[1] = p[i].c[1];
    		vbo_Data[i].gl_Vertex[2] = p[i].c[2];
    		vbo_Data[i].gl_Normal[0] = (vn[i])[0];
    		vbo_Data[i].gl_Normal[1] = (vn[i])[1];
    		vbo_Data[i].gl_Normal[2] = (vn[i])[2];
    		vbo_Data[i].ambient[0] = ambient[0];
    		vbo_Data[i].ambient[1] = ambient[1];
    		vbo_Data[i].ambient[2] = ambient[2];
    		vbo_Data[i].diffuse[0] = diffuse[0];
    		vbo_Data[i].diffuse[1] = diffuse[1];
    		vbo_Data[i].diffuse[2] = diffuse[2];
    		vbo_Data[i].specular[0] = specular[0];
    		vbo_Data[i].specular[1] = specular[1];
    		vbo_Data[i].specular[2] = specular[2];
    		vbo_Data[i].shininess = shininess;
    	glGenBuffers(1, &vbo);
    	glBindBuffer(GL_ARRAY_BUFFER, vbo);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData)*n, vbo_Data, GL_STATIC_DRAW);
    	glVertexAttribPointer(gl_VertexID, 3, GL_DOUBLE, GL_FALSE, sizeof(VertexData)*n,0);
    	glVertexAttribPointer(gl_NormalID, 3, GL_DOUBLE, GL_FALSE, sizeof(VertexData)*n, (GLvoid*) offsetof(VertexData, gl_Normal));
    	glVertexAttribPointer(ambientID, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData)*n, (GLvoid*) offsetof(VertexData, ambient));
    	glVertexAttribPointer(diffuseID, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData)*n, (GLvoid*) offsetof(VertexData, diffuse));
    	glVertexAttribPointer(specularID, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData)*n, (GLvoid*) offsetof(VertexData, specular));
    	glVertexAttribPointer(shininessID, 1, GL_FLOAT, GL_FALSE, sizeof(VertexData)*n, (GLvoid*) offsetof(VertexData, shininess));
    	glDrawArrays(GL_TRIANGLE_FAN, 0, n);
    	delete [] vbo_Data;
    glDrawArrays(GL_TRIANGLE_FAN, 0, n); generates an error when n is larger than 3
    Last edited by vickoza; 05-24-2014 at 07:10 PM. Reason: correcting misstatement

  5. #5
    Intern Contributor
    Join Date
    Mar 2014
    San Jose, CA
    The 4th argument of glVertexAttribPointer() is the stride, which is the increment in bytes between two attribute values. In your case, that should be sizeof(VertexData). Your code passes sizeof(VertexData)*n, which would be the total size of the entire array, instead.

    I would also discourage using GL_DOUBLE for your positions and normals. Many GPUs don't even support DOUBLE coordinates, and will have to convert the values to FLOAT if you pass in DOUBLE coordinates. It should be very rare that you really need the precision of a double for your coordinates.

    If a little promotion is allowed, I have an article on my personal web site that explains some typical steps needed in the transition of legacy OpenGL code to the Core Profile:

  6. #6
    Junior Member Newbie
    Join Date
    May 2014
    Thank again your argument was correct

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts