opengl glut stopped working - eclipse

I'm trying to launch hello world program using opengl and glut(eclipse). I always get message Program.exe has stopped working. I'm using windows.
I installed MinGW.
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
void displayCall() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2, 2, 2, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(.005,.005,.005);
glRotatef(20, 0, 1, 0);
glRotatef(30, 0, 0, 1);
glRotatef(5, 1, 0, 0);
glTranslatef(-300, 0, 0);
glColor3f(1,1,1);
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'H');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'e');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'l');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'l');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'o');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'W');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'o');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'r');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'l');
glutStrokeCharacter(GLUT_STROKE_ROMAN, 'd');
glutStrokeCharacter(GLUT_STROKE_ROMAN, '!');
glutSwapBuffers();
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(300, 200);
glutCreateWindow("Hello World!");
glutDisplayFunc(displayCall);
glutMainLoop();
return 0;
}
I copy glut32.dll in C:\Windows\System32 folder, glut.h in the folder C:\MinGW\include\GL and libglut32.a in C:\MinGW\lib.
I set in eclipse project->properties->c/c++ Build->Settings->MinGw c++ Linker->Libraries(add): glut32,glu32,opengl32. I don't know why it crash.

Your code compiles just fine. It also executes OK so its not a coding issue, just a library setup issue. On linux with necessary libraries installed I compiled your code using
gcc -o hello_world_glut hello_world_glut.c -lGL -lglut -lGLU
assure you are looking at the console window in Eclipse for errors

Related

Is there any replacement for "GtkRuler" in GTK3?

I want to display the horizontal and vertical ruler on the frame with gtk3.
this is my frame:
I want to display ruler on the frame like this:
BUT GtkRuler has been removed from GTK 3 for being unmaintained and too specialized!!
this is my GTK3/c cpde:
/* The horizontal ruler goes on top. As the mouse moves across the
* drawing area, a motion_notify_event is passed to the
* appropriate event handler for the ruler. */
hrule = gtk_hruler_new ();
gtk_ruler_set_metric (GTK_RULER (hrule), GTK_PIXELS);
gtk_ruler_set_range (GTK_RULER (hrule), 7, 13, 0, 20);
g_signal_connect_swapped (area, "motion_notify_event",
G_CALLBACK (EVENT_METHOD (hrule, motion_notify_event)),
hrule);
gtk_table_attach (GTK_TABLE (table), hrule, 1, 2, 0, 1,
GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0);
/* The vertical ruler goes on the left. As the mouse moves across
* the drawing area, a motion_notify_event is passed to the
* appropriate event handler for the ruler. */
vrule = gtk_vruler_new ();
gtk_ruler_set_metric (GTK_RULER (vrule), GTK_PIXELS);
gtk_ruler_set_range (GTK_RULER (vrule), 0, YSIZE, 10, YSIZE );
g_signal_connect_swapped (area, "motion_notify_event",
G_CALLBACK (EVENT_METHOD (vrule, motion_notify_event)),
vrule);
gtk_table_attach (GTK_TABLE (table), vrule, 0, 1, 1, 2,
GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0);
What ideas on how to solve this task would you suggest? Or on what resource on the internet can I find help?
If your code has a compatible license, you can simply copy the GtkRuler out of GTK 2 into your code, making any changes necessary to make it work with GTK 3.

How to draw on canvas using Cairo and GTK in Julia

I'm trying to use Julia with GTK and Cairo to draw onto a canvas. I think the following code (adapted from the example fragments on the GTK.jl page) should work, but it does not. (Other GTK widgets work, but not the canvas)
I would appreciate if someone can suggest what is wrong with this code, or give a pointer to a complete example.
using Gtk.ShortNames
using Cairo
function drawfn(w)
ctx = Gtk.getgc(w)
Cairo.set_coords(ctx, 0, 0, 800, 600, 0, 800, 0, 600)
h = Gtk.height(w)
w = Gtk.width(w)
Gtk.rectangle(ctx, 0, 0, w/2, h/2)
Gtk.set_source_rgb(ctx, 0, 0, 1)
Gtk.fill(ctx)
end
function main()
win = Gtk.#Window("stuff", 800,600)
c = Gtk.#Canvas()
Gtk.push!(win,c)
Gtk.draw(drawfn, c)
Gtk.showall(win)
end
main()
I think this was a bug in version 0.8.1 of Gtk.jl. I posted an issue to github after which vtjnash fixed it immediately and tagged version 0.8.2.

Snappy-java uncompress fails for valid data

I am trying to uncompress the bytestring using snappy-java
ByteString(0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59, 1, 14, 0, 0, 38, -104, 43, -49, 0, 0, 0, 6, 0, 0, 0, 0, 79, 75)
It contains two frames, first with chunk value 0xff(stream identifier) and length 6 and second frame of chunk type 1(uncompressed), with length 14. Which is valid as per protocol spec found [here] (http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt)
The code used to uncompress is here
val c = ByteString(0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59, 1, 14, 0, 0, 38, -104, 43, -49, 0, 0, 0, 6, 0, 0, 0, 0, 79, 75)
Snappy.uncompress(c.toArray)
The code throws FAILED_TO_UNCOMPRESS error, which is part of jna. I am using scala v2.11.3 and snappy-java v1.0.5.4
Exception in thread "main" java.io.IOException: FAILED_TO_UNCOMPRESS(5)
at org.xerial.snappy.SnappyNative.throw_error(SnappyNative.java:78)
at org.xerial.snappy.SnappyNative.rawUncompress(Native Method)
at org.xerial.snappy.Snappy.rawUncompress(Snappy.java:395)
at org.xerial.snappy.Snappy.uncompress(Snappy.java:431)
at org.xerial.snappy.Snappy.uncompress(Snappy.java:407)
Failed to uncompress error is because Snappy.uncompress does not support framed input. The framing format is finalized recently and the implemented is added in SnappyFramedInputStream. The source is located here
The following is the code to decompress snappy frames
def decompress(contents: Array[Byte]): Array[Byte] = {
val is = new SnappyFramedInputStream(new ByteArrayInputStream(contents))
val os = new ByteArrayOutputStream(Snappy.uncompressedLength(contents))
is.transferTo(os)
os.close()
os.toByteArray
}

Formatting data for CoreImage CIColorCube

I'm trying to apply arbitrary 3D Luts to images on iOS, but I'm stuck.
I can't for the life of me figure out how to correctly format the cube data for CIColorCube.
I've done what I can based on the brief screen grabs I've taken from the WWDC videos, but what I really need is some sort of working template to go from.
Are there any docs with an example of a hard coded cube rather than the procedural ICC generated ones shown in the ImageApp sample code?
Right now my cube data looks like what you see below (with the middle chopped out for brevity).
Its throwing the error:
"Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CIColorCube 0xb46a850> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key inputCubedata.'"
Any help would be much appreciated, I'm tearing my hear out over this one. I can't find any sold examples of what CIColorCube is expecting (As in a working example, not just a explanation).
uint8_t color_cube_data[4096*4] = {
0, 0, 0, 1,
17, 0, 0, 1,
33, 0, 0, 1,
51, 0, 0, 1,
68, 0, 0, 1,
84, 0, 0, 1,
102, 0, 0, 1,
119, 0, 0, 1,
-----etc etc etc
153, 255, 255, 1,
170, 255, 255, 1,
186, 255, 255, 1,
204, 255, 255, 1,
221, 255, 255, 1,
237, 255, 255, 1,
255, 255, 255, 1
};
I can't help with all your problems without more info, but I think your current error may be cause by this. Make sure the line of code setting your cube data reads like this...
[_colorCube setValue:color_cube_data forKey:#"inputCubeData"];
not this...
[_colorCube setValue:color_cube_data forKey:#"inputCubedata"];
3D LUT has to be wrapped into NSData before passed as an argument to the CIFilter. Cube values are in range [0.0 : 1.0]
NSData * cube_data = [NSData dataWithBytes:color_cube_data length:4096*sizeof(float)*4];
[filter setValue:input_image forKey:#"inputImage"];
[filter setValue:cube_data forKey:#"inputCubeData"];
[filter setValue:[NSNumber numberWithFloat:16] forKey:#"inputCubeDimension"];
Value for inputCubeDimension is strictly power of two.

How do you create a transparent truecolor PNG with Perl & GD?

It seems like a trivial problem, but nothing I've tried will make the background transparent.
use strict;
use warnings;
use GD
GD::Image->trueColor(1);
my $im = new GD::Image(100, 100);
my $clear = $im->colorAllocateAlpha(255, 255, 255, 127);
my $black = $im->colorAllocateAlpha(0, 0, 0, 0);
$im->alphaBlending(0);
$im->filledRectangle(0, 0, 100, 100, $clear);
$im->alphaBlending(1);
$im->stringFT($black, "a-ttf-font.ttf", 12, 0, 20, 20, "x");
binmode STDOUT;
print $im->png;
Thanks for any guidance.
Are you using $im->saveAlpha(1)? Otherwise the alpha information is only useful in constructing the image. The saved image won't be transparent.
A quick and dirty method, which might not be good enough for your purposes, is to forget about the alpha channel and use the GD::Image::transparent method.