Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - eawerbaneth

Pages: [1]
1
Window / Re: OpenGL and SFML Mixing in same Render Window
« on: April 16, 2012, 06:30:54 pm »
I am using 2.0, and I'm not having a problem displaying the OpenGL elements, I just couldn't get the SFML 2D elements to show up.

 RenderFunction(window);
 window.PushGLStates();
 //this does not show up
sf::Text text("testing");
 window.Draw(text);
 window.PopGLStates();
 

Since I posted the first time, I was able to build the program and getting it working using:

glBegin(GL_TRIANGLES)
//...
glEnd();
 

I'm concerned that as the project becomes bigger, it won't be efficient enough if I don't cache the information with a VBO. If you aren't aware of any blaring reason why it would work with the glBegin method and not the VBO method, I'll try scaling everything back down again and check to see if I was making a simple error.

2
Window / Re: OpenGL and SFML Mixing in same Render Window
« on: April 16, 2012, 04:25:18 pm »
Does anyone know if there is anything preventing the use of both a VBO-based OpenGL implementation and SFML 2D elements in the same window?

3
Window / OpenGL and SFML Mixing in same Render Window
« on: April 07, 2012, 08:14:19 am »
Hi,

So I've restructured my program to have the OpenGL and SFML share the same window, but I'm having trouble getting the GUI to display. I am using a different method than that shown in the OpenGL sample project in the SDK, so I wonder if there is something I am forgetting to do. My GUI will show up until I initialize my VBO (even if I don't render it), and then I can't isolate where things are going on. Just to clarify - my OpenGL cube is appearing properly, but any 2D elements fail to appear.

I am still fairly new to OpenGL, so I'm afraid that I may just be missing something small.


void CreateVBO()
{
        OpenGLObject new_obj;

        Vertices = &(new_obj.aux_vertices[0]);
        Indices = &(new_obj.aux_indices[0]);
       
        //Create a VAO and make it active
    glGenVertexArrays(1, &VaoId);
    glBindVertexArray(VaoId);
        glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    GLenum ErrorCheckValue = glGetError();
   
        const size_t BufferSize = (sizeof(*Vertices))*new_obj.aux_vertices.size();
        const size_t VertexSize = sizeof(*Vertices);
        fprintf(stderr, "Full vertex size: %d\n",sizeof(*Vertices));
        const size_t RGBOffset = sizeof((*Vertices).XYZW);
        fprintf(stderr, "RGB offset: %d\n",sizeof((*Vertices).XYZW));

    glGenBuffers(1, &BufferId);

    glBindBuffer(GL_ARRAY_BUFFER, BufferId);
    glBufferData(GL_ARRAY_BUFFER, BufferSize, Vertices, GL_STATIC_DRAW);
        glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, VertexSize, (GLvoid *)0);
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, VertexSize, (GLvoid*)RGBOffset);

        //Create buffers for vertex indices.
    glGenBuffers(1, &IndexBufferId);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBufferId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(*Indices)*new_obj.aux_indices.size(), Indices, GL_STATIC_DRAW);
       
}

void Initialize(sf::RenderWindow &window) {

        glEnable(GL_DEPTH_TEST);
        OnGLError("Depth test");
        glDepthMask(GL_TRUE);

        CreateShaders();
    CreateVBO();

}

void RenderFunction(sf::RenderWindow &window){
    window.SetActive();

        glDisable(GL_COLOR_ARRAY);
        glDisable(GL_TEXTURE_COORD_ARRAY);

        glUseProgram(ProgramId);
    OnGLError("DRAW_ERROR: Could not use the shader program");

    glClear(/*GL_COLOR_BUFFER_BIT | */GL_DEPTH_BUFFER_BIT);
        glUniformMatrix4fv(ModelMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ModelMatrix));
        glUniformMatrix4fv(ViewMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ViewMatrix));
        glUniformMatrix4fv(ProjectionMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ProjectionMatrix));
        OnGLError("ERROR: Could not set the shader uniforms");

        glBindVertexArray(VaoId);
        OnGLError("ERROR: Could not bind the VAO for drawing purposes");

        glDrawElements(GL_TRIANGLES, 10000, GL_UNSIGNED_INT, (GLvoid*)0);
        OnGLError("ERROR: Could not draw the cube");

}

int main(){
        // Create main window
        sf::RenderWindow window(sf::VideoMode(800, 600), "Sculptor");
        window.EnableVerticalSync(true);

        window.SetActive();
        ...
        Initialize(window);

        sf::Clock clock;

        // start game loop
        while(window.IsOpen()){
                ...
                //display rendered frame on screen
                RenderFunction(window);

                window.PushGLStates();
                //this does not show up
                sf::Text text("testing");
                window.Draw(text);
                window.PopGLStates();

                //display rendered frame on screen
                window.Display();

        }
        ...
}

 

4
Window / Re: Embedding an OpenGL window in a Render Window
« on: April 06, 2012, 08:53:52 pm »
Will do. Thanks for your help!

5
Window / Re: Embedding an OpenGL window in a Render Window
« on: April 06, 2012, 05:02:23 pm »
I'm trying to make my own SFML GUI for an OpenGL project that I'm also using SFML to display. I read something about being able to display 2-D SFML graphics over an OpenGL window and that I could find this in the "OpenGL sample project", but I haven't been able to find any links to that. What is the correct way of doing this?

* I'm using SFML 2.0, by the way.

6
Window / Embedding an OpenGL window in a Render Window
« on: April 06, 2012, 02:06:15 am »
Hi,

I'm having a little trouble decoding how you are supposed to embed an OpenGL window inside another window. I didn't have any luck looking for an example, and what I'm trying right now crashes upon running.

Here's what I have:
sf::RenderWindow control_window(sf::VideoMode(800, 600), "Sculptor");

sf::Window openglwindow;
sf::WindowHandle handle = control_window.GetSystemHandle();
openglwindow.Create(handle);

 

Is this the correct way to do this? Also, how would I then specify a size for the OpenGL window?

Thanks in advance!

7
Graphics / SFML 2 OpenGL Texture Issue
« on: March 05, 2012, 05:51:48 pm »
Hi,

I'm having an odd issue with texture mapping using OpenGL version 3.3.1 and SFML 2.0. I'm loading an image using SFML and applying the texture to my object in OpenGL. This words great most of the time, but sometimes after I restart my computer or putting it to sleep, the texture doesn't show up. I'm running Windows 7 64-bit with an ATI 5700 card.

Here's where I am loading the texture:
Code: [Select]

void LoadTextures(){
sf::Image img;
img.LoadFromFile("panda-model.png");
img.FlipVertically();

glGenTextures(1, &TexId);
glBindTexture(GL_TEXTURE_2D, TexId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.GetWidth(), img.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.GetPixelsPtr());
    OnGLError("img load: use program");

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

glUseProgram(ProgramId);

samplerId = glGetUniformLocation(ProgramId, "s_tex");
glActiveTexture(GL_TEXTURE0);
glUniform1i(samplerId, 0);

HGLRC test = wglGetCurrentContext();

OnGLError("pre LoadTextures: use program");
    glUseProgram(ProgramId);
OnGLError("post LoadTexutres: use program");

}


And here is my render function:

Code: [Select]

void RenderFunction(sf::Window* & app){
    app->SetActive();
    ++FrameCount;

WCtoLC[0][0] = 1;
WCtoLC[1][1] = 1;
WCtoLC[2][2] = 1;
//WCtoLC[3][1] = 4;
//WCtoLC[3][2] = 4;


NormalMatrix[0][0] = ModelMatrix[0][0];
    NormalMatrix[0][1] = ModelMatrix[0][1];
    NormalMatrix[0][2] = ModelMatrix[0][2];
    NormalMatrix[1][0] = ModelMatrix[1][0];
    NormalMatrix[1][1] = ModelMatrix[1][1];
    NormalMatrix[1][2] = ModelMatrix[1][2];
    NormalMatrix[2][0] = ModelMatrix[2][0];
    NormalMatrix[2][1] = ModelMatrix[2][1];
    NormalMatrix[2][2] = ModelMatrix[2][2];
    NormalMatrix = glm::transpose(glm::inverse(NormalMatrix));

glUseProgram(ProgramId);
    OnGLError("DRAW_ERROR: Could not use the shader program");

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUniformMatrix4fv(ModelMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ModelMatrix));
glUniformMatrix4fv(ViewMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ViewMatrix));
glUniformMatrix4fv(ProjectionMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(ProjectionMatrix));
glUniformMatrix3fv(NormalMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(NormalMatrix));
glUniformMatrix4fv(MCtoWCLoc, 1, GL_FALSE, glm::value_ptr(MCtoWC));
glUniformMatrix4fv(MCtoWCitLoc, 1, GL_FALSE, glm::value_ptr(MCtoWCit));
glUniformMatrix4fv(WCtoLCLoc, 1, GL_FALSE, glm::value_ptr(WCtoLC));
glUniformMatrix4fv(WCtoLCitLoc, 1, GL_FALSE, glm::value_ptr(WCtoLCit));

/*MCtoWCLoc = glGetUniformLocation(ProgramId, "MCtoWC");
MCtoWCitLoc = glGetUniformLocation(ProgramId, "MCtoWCit");
WCtoLCLoc = glGetUniformLocation(ProgramId, "WCtoLC");
WCtoLCitLoc = glGetUniformLocation(ProgramId, "WCtoLCit");*/

OnGLError("ERROR: Could not set the shader uniforms");


glBindTexture(GL_TEXTURE_2D, TexId);
glBindVertexArray(VaoId);
OnGLError("ERROR: Could not bind the VAO for drawing purposes");

glDrawElements(GL_TRIANGLES, 5412, GL_UNSIGNED_INT, (GLvoid*)0);
OnGLError("ERROR: Could not draw the panda");

    app->Display();
}


I'm fairly new to OpenGL, so I'm not absolutely certain that this issue is being caused by SFML or if it's something else, but please let me know your thoughts. Thank you in advance!

Pages: [1]
anything