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 - genzm

Pages: [1] 2
1
Graphics / drawing individual pixels with opengl
« on: June 11, 2013, 05:13:47 pm »
Hy,
As the title suggests I wanted to draw individual pixels to the screen. I've come a long way, but this is the essential code I've got now:
int main() {
        glewExperimental=GL_TRUE;
        glewInit();
        GLuint BUFFER;
        glGenBuffers(1,&BUFFER);
        glBindBuffer(GL_PIXEL_UNPACK_BUFFER,BUFFER);
        glBufferData(GL_PIXEL_UNPACK_BUFFER,WIDTH*HEIGHT,NULL,GL_DYNAMIC_DRAW);
        unsigned char* buffer_map = (unsigned char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
        fill_buffer(buffer_map, WIDTH, HEIGHT,objects);
}

void fill_buffer(unsigned char* buffer, unsigned int width, unsigned int height) {
        for (unsigned int pixelX = 0; pixelX < width; ++pixelX) {
                for (unsigned int pixelY = 0; pixelY < height; ++pixelY) {
                        buffer[pixelX*height+pixelY] = 255;
                }
        }

        glDrawPixels(width,height,GL_RED,GL_UNSIGNED_BYTE,buffer);
}
 

It seems to work right. The buffer is intitialised correctly, plus it is loaded with the right values (as an test I just wanted to fill my screen with red). However though, the screen stays black, instead of being red.
Anyone a suggestion why this would be?

2
Window / Re: Main while loop is not executing
« on: January 22, 2013, 09:44:52 pm »
Oh no sorry, I see.
The functions I wrote for example to check controls, all used this int to know the difference in time. Since there was no difference, nothing changed.
So, that's solved :P
Thanks for all the help everyone. I wouldn't have found it by myself.

3
Window / Re: Main while loop is not executing
« on: January 22, 2013, 09:40:09 pm »
Ok, this would explain why the title isn't updated.
But the rest of the loop (the commented draw() function), and other steps like controls,...
They should still be executed?

4
Window / Re: Main while loop is not executing
« on: January 22, 2013, 09:34:49 pm »
Oh, I see, like that :P

I tried it and it executes the loop. This is off course a better use than a simple integer.
Thanks for the tip.
But I still don't really understand why this fixed it :/

5
Window / Re: Main while loop is not executing
« on: January 22, 2013, 09:27:08 pm »
Use sf::Time instead of unsigned and do +=clock.restart() on it, you can compare them easily too, you can do like time<=sf::miliseconds(FPS_PDATE) or something. I suspect your loop goes over 1000x per second, miliseconds get truanced in C/C++ int way to 0 and debugger stepping slowed that down and let clock build few miliseconds up. If you don't know what change I'm talking about tell me and I'll make change for you to try.

Vsync can be forced off in setting for GPU and I think it only affects fullscreen.

I'm not really sure what you want to change. But indeed, when using
window.setFramerateLimit(60);
It all works just fine. I still don't really see why this solves my problem, but I'm glad I'm getting some progress.

6
Window / Re: Main while loop is not executing
« on: January 22, 2013, 09:15:18 pm »
os is windows, and i'm using visual studio c++ professional 2012.
If this would be a compiler setting (which I actually would doubt), what could I do to change it?
In debugger the code does execute and updates the title.

// edit
Another thing I just realised:
If I do add a line which prints out some text, I get a very high amount of frames per second (over a 1000). even though vertical sync is set on. Shouldn't vertical sync limit it to 60 frames?

7
Window / Re: Main while loop is not executing
« on: January 22, 2013, 08:36:16 pm »
I know I'm not supposed to use macro's, but that isn't going to solve the problem now, is it?

And yes, I used java before. But this is still my first openGL/sfml experience, so I never used JOGL.

8
Window / Re: Main while loop is not executing
« on: January 22, 2013, 08:30:44 pm »
Is used:
#define FPS_REFRESH 500


9
Window / Re: Main while loop is not executing
« on: January 22, 2013, 08:22:30 pm »
Oh, don't under estimate me :P I do have quite some experience.
I'm just new to C and C++. But yes, I am using OpenGL.

10
Window / Re: Main while loop is not executing
« on: January 22, 2013, 08:18:09 pm »
while (true) isn't good, because this will use your cpu fully.
Or at least that's what they told me :P

11
Window / Re: Main while loop is not executing
« on: January 22, 2013, 08:11:39 pm »
I use windows.
Most of the things you mention are different in my original code, but I didn't know about the stringstream, so thanks for that. :P

As for the window.clear();
Why is this a must?

12
Window / Re: Main while loop is not executing
« on: January 22, 2013, 07:59:15 pm »
No, I get the intial title, being: "First Person Shooter".
And maybe just as a tip, what do find so ugly about the code?

13
Window / Main while loop is not executing
« on: January 22, 2013, 07:13:43 pm »
Hy,
I've been working on graphics application for a while, but suddenly I'm experiencing some trouble with it. Somehow the main loop is not being executed. I've managed to make a simple example which still shows my problem:

sf::Window window(sf::VideoMode(1024, 576), "First Person Shooter");
        window.setVerticalSyncEnabled(true); // 60 FPS

        sf::Clock c;
        unsigned int fps_counter = 0;
        unsigned int fps = 0;

        while (true)
        {
                sf::Time time = c.getElapsedTime();
                c.restart();
                unsigned int ms = time.asMilliseconds();

                fps_counter += ms;
                ++fps;
                if(fps_counter >= FPS_REFRESH) {
                        char buffer[32];
                        int av = (int) (fps * 1000) / fps_counter;
                        sprintf(buffer, "%d - frames per second", av);
                        window.setTitle(buffer);

                        // reset
                        fps_counter = 0;
                        fps = 0;
                }

                //draw();

                window.display();
        }

        window.close();

What I'm trying to do is to print out the frames per second. But the title of the window is never updated...
I suppose I'm overlooking something very easy... :/
Anyone a suggestion?

// edit
Forgot to mention this:
When I add one line in the loop, for example
cout << "test" << endl;
It all suddenly works.

14
Graphics / Re: textures in opengl
« on: January 04, 2013, 11:31:35 am »
Maybe one last question:
If I wanted to use multiple textures at once (for example: color texture and shadow map). How could I do this? Since no 2 textures can be bound at the same time?

15
Graphics / Re: textures in opengl
« on: January 03, 2013, 12:40:25 pm »
Thanks for your concern, but I know how to use C++ memory allocation.
I know it's not right to allocate everything, and as I said before: In my original code not everything is allocated on the heap.

As for the materials. You are right, cases like that will probably never occur. So I'm going to make some modificatioins around there.

Pages: [1] 2