I am a long time programmer who is finally taking the plunge ito open GL… I can’t get this simple program to behave the way I would expect it to. I’m simply trying to draw a 100x100 square full of randomly colored pixels. Instead, I get a square with randomly colored pixels, and a severe vertical striping type effect. I have tried everything I could think of with glPixelStorei, but It doesn’t change…
//Graphical "Hello World" routine : random square
glDrawPixels(100, 100, GL_RGB, GL_UNSIGNED_BYTE,Square);
THANKS FOR YOUR HELP GUYS!
How about using:
Your code allocates 30000 byte pointers, the second allocates 30000 bytes.
This means that each random value you put in there will use up 4 bytes NOT one as I assume you want.
The result would be 1 random colord pixel and 3 black pixels and then same thing over and over again, is this the problem you have ?
Sounds like disabled v-sync. Set V-Sync to be enabled on default under windows. (Desktop->Right Click -> Properties -> Display Settings -> Advanced Settings).
I knew it was something stupid like that!
I am learning Cocoa and oGL at the same time after many many years of C++ and Intel 13h graphics expereince. I know algoritms and theory but I’m a newbie once again in the actual implimentation and syntax. I’m trying to figure out the best way to hold large arrays for graphics. (Which can then be manipulated with my algorithms)
So in that note, what’s wrong with:
The same program from above, when enlarged to 720x486 instead of 100x100 crashes.
thanks for your help guys
MAybe its not the best idea to allocate huge arrays on stack.
(Psst I’m a mathematician not a programmer… some crossover, but not with stuff like dealing with the memory… still learning)
I have noticed in my educational life in general, that people are often severely lacking in fundamentals. Instructors so often glaze over the very basic “moves” in math and related subjects. The instructors categorize them as “automatic”, in their own minds, and then the importance is lost on the students.
This is why I will ask questions, even stupid ones, because I am trying to build up the fundamentals of programming.
So thanks <me>… now I know that not only is it “bad” to declare large array variables inside “the stack” but it actually crashes the program. Thats good, (now obvious) important information for a beginner that none of the literature I read mentioned.
And this is after I have already written things like realtime fourier transformers and other “advanced” programs.
Teaching yourself something is really hard because these fundamentals are rarely adressed directly. So the web boards like this become EXTREMELY valuable!
GLUbyte* vector = (GLUbyte*) malloc( 1001003);
… do something with it…
Or you can of course use new/delete instead in C++.
The space available on the stack is usually not that big by default even though many times you can set it with an argument to the linker.
So use malloc/free or new/delete for larger objects.