Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!

We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

A Few Questions Regarding OpenGL

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Toothpix   Crossbones+   -  Reputation: 810


Posted 10 February 2013 - 04:09 PM

I recently started creating my first shader-based OpenGL program in a limited subset of 3.2, but can you have more than one program object? I created a program object for both the vertex and fragment shaders, and attached their respective shaders to them and linked them. I started the entire program (after windowing and contexts) with the createShader function, then I compiled and attached to program, then the same for the fragment shader. Am I starting correctly?
Also, is OpenGL 3.2 easily portable to ES 2 if I use no geometry shaders? What if I do?
 P.S: Here is my rendering source code thus far:
#include <windows.h>
#include <GL/glew.h>
#include <GL/glext.h>
#include <GL/gl.h>
#include "renderMain.h"
#include "fileAccess.h"

#define ULONG unsigned long

    /* Creating and Compiling the Primary Vertex Shader */
    GLuint vertShader = 0;
    vertShader = glCreateShader(VERTEX_SHADER);
    glShaderSource(vertShader, /*insert parameter*/ , /*insert parameter*/);

    /* Creating and Compiling the Primary Fragment Shader */
    GLuint fragShader = 0;
    fragShader = glCreateShader(FRAGMENT_SHADER);
    glShaderSource(fragShader, /*insert parameter*/ , /*insert parameter*/);

    /* Creating Vertex Program */
    GLuint progObjVert = 0;
    progObjVert = glCreateProgram();
    glAttachShader(progObjVert, vertShader);

    /* Creating Fragment Program */
    GLuint progObjFrag = 0;
    progObjFrag = glCreateProgram();
    glAttachShader(progObjVert, fragShader);



Where I put the "insert parameter" comments is where I will use pointers from the fileAccess source file to get shaders from a file. Also, this is called from main() which is in main.c, which is where all of the windowing and context handling is. But is this the proper way to start out? I can add main.c if that is important.

C dominates the world of linear procedural computing, which won't advance. The future lies in MASSIVE parallelism.


#2 TheChubu   Crossbones+   -  Reputation: 4564


Posted 10 February 2013 - 04:32 PM

You should attach to a program all you want to use for your draw call.


The fragments are created out of the projection of the geometry in the vertex shader. How your program that has the fragment shader will access the data that your first program with the vertex shader processed? 


In a single program you attach all you need (vertex, fragment, etc). And then you can make your draw call that will use the shaders that you linked to your program.


Now, you can use several programs because not all things are drawn the same, ie, not everything uses the same shader.



My journals: dustArtemis ECS framework and Making a Terrain Generator

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.