void GLFWCALL set_window_size(int w, int h) { *window_width() = w; *window_height() = h; glfwSetMousePos(*window_width()/2, *window_height()/2); window_set_perspective(); }
void window_set_perspective() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, *window_width(), *window_height()); gluPerspective(45, *window_width()/(float)*window_height(), 0.01, 1000); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); }
void window_set_2d() { int half_width = *window_width() / 2; int half_height = *window_height() / 2; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, *window_width(), *window_height()); gluOrtho2D(-half_width, half_width, -half_height, half_height); glMatrixMode(GL_MODELVIEW); glDisable(GL_DEPTH_TEST); }
static void draw(void) { VGint WINDSIZEX = window_width(); VGint WINDSIZEY = window_height(); VGPaint fill; VGPath box; VGfloat color[4] = {1.f, 0.f, 0.f, 1.f}; VGfloat bgCol[4] = {0.7f, 0.7f, 0.7f, 1.0f}; VGfloat transCol[4] = {0.f, 0.f, 0.f, 0.f}; VGImage image = vgCreateImage(VG_sRGBA_8888, img_width, img_height, VG_IMAGE_QUALITY_NONANTIALIASED); /* Background clear */ fill = vgCreatePaint(); vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); vgSetPaint(fill, VG_FILL_PATH); box = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); /* Rectangle to cover completely 16x16 pixel area. */ RectToPath(box, 0, 0, 64, 64); vgSetfv(VG_CLEAR_COLOR, 4, transCol); vgClearImage(image, 0, 0, img_width, img_height); vgSetfv(VG_CLEAR_COLOR, 4, color); vgClearImage(image, 10, 10, 12, 12); //vgImageSubData(image, pukki_64x64_data, pukki_64x64_stride, // VG_sRGBA_8888, 0, 0, 32, 32); vgSeti(VG_MASKING, VG_TRUE); vgLoadIdentity(); vgSetfv(VG_CLEAR_COLOR, 4, bgCol); vgClear(0, 0, WINDSIZEX, WINDSIZEY); vgMask(image, VG_FILL_MASK, 0, 0, window_width(), window_height()); vgMask(image, VG_SET_MASK, x_pos, y_pos, 100, 100); vgDrawPath(box, VG_FILL_PATH); //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); //vgTranslate(-10, -10); //vgDrawImage(image); vgDestroyPaint(fill); vgDestroyPath(box); }
wykobi_window(int argc, char* argv[]) { display_mode = eDisplayMode2D; handle = this; glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(window_width(),window_height()); glutInitWindowPosition(window_position_x(),window_position_y()); glutInit(&argc,argv); glutCreateWindow(window_title().c_str() ); glutKeyboardFunc(glut_keyboard_handler ); glutSpecialFunc (glut_special_key_handler); glutReshapeFunc (glut_reshape_handler ); glutDisplayFunc (glut_display_handler ); glutMouseFunc (glut_mouse_handler ); glutMotionFunc (glut_motion_handler ); glutCreateMenu (glut_menu_handler ); glutIdleFunc (glut_idle_handler ); if (handle->display_mode == eDisplayMode2D) { glClearColor (0.0, 0.0, 0.0, 0.0); gluOrtho2D (0.0, handle->window_width()-1, handle->window_height()-1,0.0); glDisable(GL_DEPTH_TEST); } }
int init_form_window(char *name, int cols) { XSetWindowAttributes wa; /* The X attributes structure */ /* First allocate memory for the new window structure */ gWindow = alloc_hd_window(); open_form_window(); gWindow->width = window_width(cols); if (name == NULL) { /** Then allocate an empty page, and assign it to gWindow->page */ gWindow->page = alloc_page((char *) NULL); } else { /* Try to find the page in the page hash table */ gWindow->page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, name); if (gWindow->page == NULL) { fprintf(stderr, "Couldn't find page %s\n", name); return (-1); } } get_GCs(gWindow); hash_insert(&gSessionHashTable, (char *)gWindow,(char *) &gWindow->fMainWindow); wa.background_pixel = gBackgroundColor; XChangeWindowAttributes(gXDisplay, gWindow->fMainWindow, CWBackPixel, &wa); XChangeWindowAttributes(gXDisplay, gWindow->fScrollWindow, CWBackPixel,&wa); return 1; }
static void draw(void) { vgClear(0, 0, window_width(), window_height()); vgDrawPath(path, VG_FILL_PATH); vgFlush(); }
/* ------------------------------------------------------------------------- */ void mouse_position_callback(GLFWwindow* window, double xpos, double ypos) { /* convert to GL screen space, then fire */ double norm_x, norm_y; norm_x = (xpos * 2.0 / (double)window_width()) - 1.0; norm_y = 1.0 - (ypos * 2.0 / (double)window_height()); EVENT_FIRE2(evt_mouse_move, norm_x, norm_y); }
static void draw(void) { vgClear(0, 0, window_width(), window_height()); vgLoadIdentity(); vgTranslate(50, 21); vgDrawPath(path, VG_FILL_PATH); vgFlush(); }
void draw( Mesh& m, const Transform& model, const Orbiter& camera, GLuint texture ) { // recupere les transformations Transform view= orbiter_view_transform(camera); Transform projection= orbiter_projection_transform(camera, window_width(), window_height(), 45); // affiche l'objet draw(m, model, view, projection, texture); }
void text::print(const float x, const float y, const rgba &col, const std::string &s) { SDL_Color c = { (unsigned char)(col.r() * 255.0f), (unsigned char)(col.g() * 255.0f), (unsigned char)(col.b() * 255.0f) }; SDL_Surface *message = TTF_RenderText_Blended(_font, s.c_str(), c); unsigned int texture = 0; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, message->w, message->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, message->pixels); glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); bool reenableLighting = false; if (glIsEnabled(GL_LIGHTING)) { glDisable(GL_LIGHTING); reenableLighting = true; } scene::resize_2d(window_width(), window_height()); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(x + message->w, y, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(x + message->w, y + message->h, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + message->h, 0.0f); glEnd(); glDeleteTextures(1, &texture); SDL_FreeSurface(message); if (reenableLighting) { glEnable(GL_LIGHTING); } glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); }
static void draw(void) { const VGint w = 48; VGImage img1, img2; VGint x, y; vgSetfv(VG_CLEAR_COLOR, 4, white); vgClear(0, 0, window_width(), window_height()); img1 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); img2 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); x = 5; y = (window_height() - w) / 2; /* test vgSetPixels */ vgSetfv(VG_CLEAR_COLOR, 4, red); vgClearImage(img1, 0, 0, w, w / 2); vgSetfv(VG_CLEAR_COLOR, 4, black); vgClearImage(img1, 0, w / 2, w, w / 2); vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgDrawImage */ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(x, y); vgDrawImage(img1); /* test vgGetPixels */ vgGetPixels(img1, 0, 0, x, y, w, w); x += w + 5; vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgCopyImage */ vgCopyImage(img2, 0, 0, img1, 0, 0, w, w, VG_FALSE); vgSetPixels(x, y, img2, 0, 0, w, w); /* vgCopyPixels */ vgCopyPixels(x + w + 5, y, x, y, w, w); vgDestroyImage(img1); vgDestroyImage(img2); }
static void draw(void) { VGfloat point[2], tangent[2]; int i = 0; vgClear(0, 0, window_width(), window_height()); vgSetPaint(fill, VG_FILL_PATH); vgDrawPath(path, VG_FILL_PATH); draw_marks(path); vgFlush(); }
static void draw(void) { VGPath line; VGPaint fillPaint; VGubyte lineCommands[3] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS}; VGfloat lineCoords[] = {-2.0f,-1.0f, 0.0f,0.0f, -1.0f, -2.0f}; VGfloat clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f};/* black color */ VGfloat fillColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */ //VGfloat testRadius = 60.0f; VGfloat testRadius = 10.0f; int WINDSIZEX = window_width(); int WINDSIZEY = window_height(); line = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); fillPaint = vgCreatePaint(); vgSetf(VG_STROKE_LINE_WIDTH, 1.0f); //vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); //vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(60, 60); vgScale(testRadius * 2, testRadius * 2); vgAppendPathData(line, 3, lineCommands, lineCoords); vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgSetPaint(fillPaint, VG_STROKE_PATH); vgSetParameterfv(fillPaint, VG_PAINT_COLOR, 4, fillColor); vgSetParameteri( fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgClear(0, 0, WINDSIZEX, WINDSIZEY); vgDrawPath(line, VG_STROKE_PATH); vgDestroyPath(line); vgDestroyPaint(fillPaint); }
static void draw(void) { static const VGint red_pixel = 255 << 24 | 255 << 16 | 0 << 8 | 0; static const VGint blue_pixel = 255 << 24 | 0 << 16 | 0 << 8 | 255; VGint i; vgSetfv(VG_CLEAR_COLOR, 4, red_color); vgClear(0, 0, window_width(), window_height()); vgFlush(); memset(data, 0, window_width() * window_height() * sizeof(VGint)); vgReadPixels(data, window_width() * sizeof(VGint), VG_lARGB_8888, 0, 0, window_width(), window_height()); fprintf(stderr, "Red 0 = 0x%x and at 600 = 0x%x\n", data[0], data[600]); for (i = 0; i < window_width() * window_height(); ++i) { assert(data[i] == red_pixel); } vgSetfv(VG_CLEAR_COLOR, 4, blue_color); vgClear(50, 50, 50, 50); vgFlush(); memset(data, 0, window_width() * window_height() * sizeof(VGint)); vgReadPixels(data, 50 * sizeof(VGint), VG_lARGB_8888, 50, 50, 50, 50); fprintf(stderr, "Blue 0 = 0x%x and at 100 = 0x%x\n", data[0], data[100]); for (i = 0; i < 50 * 50; ++i) { assert(data[i] == blue_pixel); } }
NE_API void reset_scissor() { glScissor(0, 0, window_width(), window_height()); }
DECLARE_TEST( window, sizemove ) { window_t* window; #if FOUNDATION_PLATFORM_MACOSX window = window_allocate_from_nswindow( delegate_nswindow() ); #elif FOUNDATION_PLATFORM_IOS window = window_allocate_from_uiwindow( delegate_uiwindow() ); #endif EXPECT_NE( window, 0 ); EXPECT_TRUE( window_is_open( window ) ); thread_sleep( 1000 ); #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID EXPECT_TRUE( window_is_maximized( window ) ); #else EXPECT_FALSE( window_is_maximized( window ) ); #endif EXPECT_TRUE( window_is_visible( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_maximize( window ); thread_sleep( 1000 ); EXPECT_TRUE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); #if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID window_restore( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); #endif window_maximize( window ); thread_sleep( 1000 ); EXPECT_TRUE( window_is_maximized( window ) ); #if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID window_resize( window, 150, 100 ); thread_sleep( 1000 ); EXPECT_EQ( window_width( window ), 150 ); EXPECT_EQ( window_height( window ), 100 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_move( window, 10, 20 ); thread_sleep( 1000 ); EXPECT_EQ( window_position_x( window ), 10 ); EXPECT_EQ( window_position_y( window ), 20 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_minimize( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_FALSE( window_has_focus( window ) ); window_restore( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_FALSE( window_is_minimized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_minimize( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_is_minimized( window ) ); #endif window_deallocate( window ); window = 0; EXPECT_FALSE( window_is_open( window ) ); return 0; }
int draw( void ) { if(wireframe) { glClearColor(1, 1, 1, 1); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(2); } else { glClearColor(0.2f, 0.2f, 0.2f, 1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } // effacer l'image glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(key_state('r')) { clear_key_state('r'); reload_program(); } // recupere les mouvements de la souris int mx, my; unsigned int mb= SDL_GetRelativeMouseState(&mx, &my); int mousex, mousey; SDL_GetMouseState(&mousex, &mousey); // deplace la camera if(mb & SDL_BUTTON(1)) orbiter_rotation(camera, mx, my); // tourne autour de l'objet else if(mb & SDL_BUTTON(2)) orbiter_translation(camera, (float) mx / (float) window_width(), (float) my / (float) window_height()); // deplace le point de rotation else if(mb & SDL_BUTTON(3)) orbiter_move(camera, mx); // approche / eloigne l'objet // recupere les transformations Transform model= make_identity(); Transform view= orbiter_view_transform(camera); Transform projection= orbiter_projection_transform(camera, window_width(), window_height(), 45); Transform viewport= make_viewport(window_width(), window_height()); Transform mvp= projection * view * model; Transform mvpInv= make_inverse(mvp); Transform mv= model * view; // affiche l'objet if(program_failed == false) { if(key_state('w')) { clear_key_state('w'); wireframe= !wireframe; } // configuration minimale du pipeline glBindVertexArray(vao); glUseProgram(program); // affecte une valeur aux uniforms // transformations standards program_uniform(program, "modelMatrix", model); program_uniform(program, "modelInvMatrix", make_inverse(model)); program_uniform(program, "viewMatrix", view); program_uniform(program, "viewInvMatrix", make_inverse(view)); program_uniform(program, "projectionMatrix", projection); program_uniform(program, "projectionInvMatrix", make_inverse(projection)); program_uniform(program, "viewportMatrix", viewport); program_uniform(program, "viewportInvMatrix", make_inverse(viewport)); program_uniform(program, "mvpMatrix", mvp); program_uniform(program, "mvpInvMatrix", mvpInv); program_uniform(program, "mvMatrix", mv); program_uniform(program, "normalMatrix", make_normal_transform(mv)); // interactions program_uniform(program, "viewport", make_vec2(window_width(), window_height())); program_uniform(program, "time", (float) SDL_GetTicks()); program_uniform(program, "motion", make_vec3(mx, my, mb & SDL_BUTTON(1))); program_uniform(program, "mouse", make_vec3(mousex, mousey, mb & SDL_BUTTON(1))); // textures for(unsigned int i= 0; i < (unsigned int) textures.size(); i++) { char uniform[1024]; sprintf(uniform, "texture%d", i); program_use_texture(program, uniform, i, textures[i]); } // go glDrawArrays(GL_TRIANGLES, 0, vertex_count); } // affiche les infos begin(widgets); if(program_failed) { label(widgets, "[error] program '%s'", program_filename.path); begin_line(widgets); text_area(widgets, 20, program_log.c_str(), program_area); } else { label(widgets, "program '%s' running...", program_filename.path); if(mesh_filename[0] != 0) { begin_line(widgets); label(widgets, "mesh '%s', %u positions, %u texcoords, %u normals", mesh_filename.path, (unsigned int) mesh.positions.size(), (unsigned int) mesh.texcoords.size(), (unsigned int) mesh.normals.size()); } for(unsigned int i= 0; i < (unsigned int) texture_filenames.size(); i++) { begin_line(widgets); label(widgets, "texture%u '%s'", i, texture_filenames[i].path); } } end(widgets); draw(widgets, window_width(), window_height()); if(key_state('s')) { clear_key_state('s'); screenshot("shader_kit.png"); } if(key_state('c')) { clear_key_state('c'); write_orbiter(camera, "orbiter.txt"); } if(key_state('v')) { clear_key_state('v'); camera= read_orbiter("orbiter.txt"); } return 1; }