Jump to content
  • Advertisement
Sign in to follow this  
amp47

OpenGL i have opengl problem please help me finding that

This topic is 1488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi everyone

i want to follow a tutorial series and i just do everything but the seen still blank first this what I've done till now

i use the classes   gameWindow ,renderSystem VertexBuffer,ShaderInterface,shaderLoader and ResourceManger.

i create the gameWindow inside it take a refrence to rendersystem and setup the context inside the gamewindow and take it bake on renderSytem i use this lines on render method

void RenderSystem::render(VertexBuffer *vertexBuffer){


    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glUseProgram((vertexBuffer->getShader())->get_programHandle());
    glLoadIdentity();

    gluLookAt(0.0f,0.0f,-5.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);

    vertexBuffer->configureVertexAttributes();
    vertexBuffer->renderVertexBuffer();

    glfwSwapBuffers(_window);
    glfwPollEvents();

}

and callback this method on game loop

the resoureceManager has a vector of vertex buffer and i pass the first element from this vector to the render method

the vertexbuffer file is

#include "VertexBuffer.h"

VertexBuffer::VertexBuffer(GLvoid *data,GLsizeiptr dataSize,GLenum mode,GLsizei Count,GLsizei stride,ShaderInterface *shader):
_mode(mode),_stride(stride),_count(Count),_shader(shader)
{
    glGenBuffers(1,&_vertexBufferId);
    glBindBuffer(GL_ARRAY_BUFFER,_vertexBufferId);
    glBufferData(GL_ARRAY_BUFFER,dataSize,data,GL_STATIC_DRAW);
}

GLuint VertexBuffer::getVertexBufferId(){
    return _vertexBufferId;
}

void VertexBuffer::configureVertexAttributes(){
    if(_shader->get_aPositionVertex()!=-1){
        glEnableVertexAttribArray(_shader->get_aPositionVertex());
        glVertexAttribPointer(_shader->get_aPositionVertex(),3,GL_FLOAT,GL_FALSE,_stride,NULL);
    }

}

ShaderInterface *VertexBuffer::getShader(){
    return _shader;
}
void VertexBuffer::renderVertexBuffer(){
    glDrawArrays(_mode,1,_count);
}


VertexBuffer::~VertexBuffer()
{
    glDeleteBuffers(1,&_vertexBufferId);
    _vertexBufferId=0;
}

i have create the buffer on the resourceManager on the constructor

#include "ResourceManager.h"
#include "Vertecies.h"

ResourceManager::ResourceManager()
{
    _shaderArray= new  std::vector <ShaderInterface *>();
    ShaderInterface *shader=new ShaderInterface("ColorSharder.vs","ColorSharder.fs");
    _shaderArray->push_back(shader);
    _vertexbufferArray= new  std::vector <VertexBuffer *>();

     VertexBuffer *vertexBuffer=new VertexBuffer(vertices,sizeof(vertices),GL_TRIANGLES,3,3*sizeof(GLfloat),_shaderArray->at(0));

     _vertexbufferArray->push_back(vertexBuffer);

}

std::vector <ShaderInterface *>*ResourceManager::getShaderArray(){
        return _shaderArray;
}

std::vector <VertexBuffer *>*ResourceManager::getVertexBuffer(){
        return _vertexbufferArray;
}

ResourceManager& ResourceManager::getResourceManager()
{
    ResourceManager *resourceManager=NULL;
    if(resourceManager==NULL){
        resourceManager=new ResourceManager();
    }
    return *resourceManager;
}

void ResourceManager::destroyResourceManager()
{
     ResourceManager *resourceManager=&getResourceManager();
     delete resourceManager;
}

ResourceManager::~ResourceManager()
{
    for(std::vector<ShaderInterface *>::iterator step=_shaderArray->begin();step!=_shaderArray->end();step++){
        delete *step;
    }
    delete _shaderArray;
    for(std::vector<VertexBuffer *>::iterator step=_vertexbufferArray->begin();step!=_vertexbufferArray->end();step++){
        delete *step;
    }
    delete _vertexbufferArray;
}

the bufferLoudaer is present below and i think is work just find because it print the index on buffer

#include "ShaderLoader.h"
#include <stdio.h>

ShaderLoader::ShaderLoader(const char *vs,const char *fs)
{
        glfwGetCurrentContext();

        GLenum err = glewInit();
        if (GLEW_OK != err)
                {
                 std::cout<<glewGetErrorString(err);
                }
    _programeHandl=glCreateProgram();
    GLuint vertexShader=CompileSharder(GL_VERTEX_SHADER,vs);
    GLuint fragmentShader=CompileSharder(GL_FRAGMENT_SHADER,fs);

    glAttachShader(_programeHandl,vertexShader);
    glAttachShader(_programeHandl,fragmentShader);

    glLinkProgram(_programeHandl);

    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);

}

GLuint ShaderLoader::getProgramehandl(){
    return _programeHandl;
}

GLuint ShaderLoader::CompileSharder(GLenum shader,const char *source){
    GLuint shaderHandle=glCreateShader(shader);
    glShaderSource(shaderHandle,1,&source,NULL);
    glCompileShader(shaderHandle);
    std::cout<<shaderHandle<<"\n";
    // check for compile errors
    int params = -1;
    glGetShaderiv (shaderHandle, GL_COMPILE_STATUS, &params);
    if (GL_TRUE != params) {
      fprintf (stderr, "ERROR: GL shader index %i did not compile\n", shaderHandle);

      return false; // or exit or something
    }
    return shaderHandle;
}
ShaderLoader::~ShaderLoader()
{
    glDeleteProgram(_programeHandl);
}

the shaders i am use


#version 400
attribute vec3 aPositionVertex;

void main () {
  gl_Position =vec4 (aPositionVertex, 1.0);
}

//fragment shader
#version 400
uniform vec4 uColor;

void main () {
  //frag_colour = uColor;
  gl_FragColor= uColor;
}

i get the attributes from the shaderinterface with get_uColor() and get_aPositionVertex()

but i don't know how to pass the vertexbuffer to this pointer

 _vertexShaderString=readShaderFile(fileVs);
    _fragmentShaderString=readShaderFile(fileFs);

    _shader=new ShaderLoader(_vertexShaderString,_fragmentShaderString);

    _aPositionVertex=glGetAttribLocation(_shader->getProgramehandl(),"aPositionVertex");
    _uColor=glGetUniformLocation(_shader->getProgramehandl(),"uColor");

Share this post


Link to post
Share on other sites
Advertisement

Something I'm missing from the code snippets in the OP is the use of a vertex array object (VAO) what is mandatory since OpenGL 3.2 core or so. That nothing is rendered is a known effect when it is missed.

 

However, really many things can be wrong. I don't see any error checking (no glGetError(), glGetShaderiv(..., GL_COMPILE_STATUS, ...) and so on).

Share this post


Link to post
Share on other sites

It's odd you're expecting that gluLookAt() will affect anything, while your shader wont' transform vertices at all.

 

And you're mixing old api with new gl (judging by #version 400). Built-in uniforms was deprecated since GL 3.0

It's not that it won't work at all, it's still there in compatibility profile, but kinda lame...

Share this post


Link to post
Share on other sites

the compile share checking its true and the aPositionVertex its 0

i have try using the vao it's working but i didn't get very well so i decide to follow that tutorial step by step

i don understand where i can transform the vertices to shader

i am use this to compile and load shader

#include "ShaderLoader.h"
#include <stdio.h>

ShaderLoader::ShaderLoader(const char *vs,const char *fs)
{
        glfwGetCurrentContext();

        GLenum err = glewInit();
        if (GLEW_OK != err)
                {
                 std::cout<<glewGetErrorString(err);
                }
    _programeHandl=glCreateProgram();
    GLuint vertexShader=CompileSharder(GL_VERTEX_SHADER,vs);
    GLuint fragmentShader=CompileSharder(GL_FRAGMENT_SHADER,fs);

    glAttachShader(_programeHandl,vertexShader);
    glAttachShader(_programeHandl,fragmentShader);

    glLinkProgram(_programeHandl);

    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);

}

GLuint ShaderLoader::getProgramehandl(){
    return _programeHandl;
}

GLuint ShaderLoader::CompileSharder(GLenum shader,const char *source){
    GLuint shaderHandle=glCreateShader(shader);
    glShaderSource(shaderHandle,1,&source,NULL);
    glCompileShader(shaderHandle);
    std::cout<<shaderHandle<<"\n";
    // check for compile errors
    int params = -1;
    glGetShaderiv (shaderHandle, GL_COMPILE_STATUS, &params);
    if (GL_TRUE != params) {
      fprintf (stderr, "ERROR: GL shader index %i did not compile\n", shaderHandle);

      return false; // or exit or something
    }
    return shaderHandle;
}
ShaderLoader::~ShaderLoader()
{
    glDeleteProgram(_programeHandl);
}

and please i want the basics on ho to draw something  i meant what i have to pass and bind just steps

Share this post


Link to post
Share on other sites

you should make matrix class and apply it to your program 

then whenever you want to draw something i send mvp matrix to the shader and it transforms  vertices position for you  by matrix * vertex multiplication

Edited by WiredCat

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!