Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - gf_layer_attach() failed !!!: Page 1 of 8 (8 Items)
   
gf_layer_attach() failed !!!  
Dear All,

Dear All,

I am new to qnx GF, I have read “Advanced Graphics Developers Guide.pdf” and trying to draw a rectangle on GF. I have 
x86 target machine connected to QNX Momentics IDE 4.7.

gf_layer_attach() is failed... can some help...

find output and code below.

Output:
Number of displays: 1
Display 0: 1024X768, refresh = 60Hz
Number of layers: 1

code snippet:

#include <stdio.h>
#include <stdlib.h>
#include <gf/gf.h>




int main() {

//device & display
gf_dev_t            gdev;
gf_dev_info_t       gdev_info;
gf_display_t        display;
gf_display_info_t   display_info;
int i;

//layer
gf_layer_t  layer;

//surface
gf_surface_t    surface;
unsigned height;
unsigned width;
gf_layer_info_t layer_info;

//context
gf_context_t context;


if (gf_dev_attach(&gdev, GF_DEVICE_INDEX(0), &gdev_info) != GF_ERR_OK) {
    printf("gf_dev_attach() failed\n");
    return (-1);
}

printf("Number of displays: %d\n",gdev_info.ndisplays);

for (i = 0; i < gdev_info.ndisplays; i++) {
    printf("Display %d: ", i);
    if (gf_display_attach(&display, gdev, i, &display_info) == GF_ERR_OK) {
        printf("%dX%d, refresh = %dHz\n", display_info.xres,
            display_info.yres, display_info.refresh);
        printf("Number of layers: %d\n", display_info.nlayers);
    } else {
        printf("gf_display_attach() failed\n");
    }
}

if (display != NULL) {


    if (gf_layer_attach(&layer,display,display_info.main_layer_index, 0) == GF_ERR_OK) {
    //if(gf_layer_attach(&layer,display,0, 0) == GF_ERR_OK) {
		printf("Attaching to Layer : 2\n ");
    }
    else {
        printf("gf_layer_attach() failed\n");
    }
}

if((gf_layer_query(layer,0,&layer_info))==GF_ERR_OK){
	printf("Layer is of Format %d\n",layer_info.format);
}
else{
	printf(" gf_layer_query() failed");
}

width = display_info.xres;
height = display_info.yres;

if (gf_surface_create_layer(&surface, &layer, 1, 0,
width, height, layer_info.format, NULL, 0) == GF_ERR_OK) {
		printf("Succesfully created surface on top of layer\n");
        gf_layer_set_surfaces(layer, &surface, 1);

        /* draw stuff here */

    } else {
        printf("gf_surface_create_layer() failed\n");
    }

if (gf_context_create(&context) != GF_ERR_OK) {
        fprintf(stderr, "gf_context_create failed\n");
        return -1;
    }

else{
printf(" Created the context succefully\n");
}


if (gf_context_set_surface(context,surface)!= GF_ERR_OK) {
            fprintf(stderr, "gf_context_set_surface failed\n");
            return -1;
        }
 else{
        printf("Context Surface is Set Succesfully\n");
        }





gf_draw_begin(context);


gf_context_set_fgcolor(context,0xFFFFFF);
gf_draw_rect(context,10,10,50,50);

gf_context_set_fgcolor(context,0x000000);
gf_draw_rect(context,20,20,40,40);
gf_draw_end(context);
gf_dev_detach(gdev);
return 0;
}



Attachment: Text draw.c 2.51 KB