ich habe bisher meine X11 Fenster immer via XCreateWindow erstellt und dabei direkt das visual übergeben welches ich via glXChooseVisual erhalte.
Jetzt möchte ich das ganze aber gern etwas umstellen, ERST das Fenster erstellen und DANN den OpenGL kram initialisieren. das bedeutet aber das ih bei XCreateWindow kein visual übergeben kann, sondern das DefaultVisual nehmen müßte (und die DefaultDepth).. kann ich das im nachhinein noch ändern?
Registriert: Di Jul 01, 2003 18:59 Beiträge: 887 Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Here is an minimal delphi/freepascal linux example:
Code:
{******************************************************************************} { } { OpenGl 1.2 Template for Kylix using the X-Server } { } { Copyright (C) by the members of the DGL Community } { All Rights Reserved. } { } { Obtained through: } { Delphi OpenGL Community(DGL) } { } { You may retrieve the latest version of this file at the Delphi OpenGL } { Community home page, located at http://www.delphigl.com/ } { } { The contents of this file are used with permission, subject to } { the Mozilla Public License Version 1.1 (the "License"); you may } { not use this file except in compliance with the License. You may } { obtain a copy of the License at } { http://www.mozilla.org/MPL/MPL-1.1.html } { } { Software distributed under the License is distributed on an } { "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or } { implied. See the License for the specific language governing } { rights and limitations under the License. } { } {-- Project-Infos -------------------------------------------------------------} { Project : OpenGl 1.2 Template for Kylix using the X-Server } { Module : Main Project File } { Createt at : 18/06/2004 } { Created by : Noeska } { Compiled with : ---- } { } {-- History -------------------------------------------------------------------} { Version | Date | User | Notes } {------------------------------------------------------------------------------} { 1.0 | 18/06/04 | Noeska | } { 1.1 | 2010 | Noeska | Freepascal compatible and use of shaders } {******************************************************************************}
//VAO VBO vaoID: array [0..1] of GLuint; vboID: array [0..1] of GLuint;
{------------------------------------------------------------------} { Function to draw the actual scene } {------------------------------------------------------------------} procedure glDraw(); begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
//use simple shader program //glslsimpleprog.Enable;
glBindVertexArray(vaoID[0]); // select first VAO glDrawArrays(GL_TRIANGLES, 0, 3); // draw first object
glBindVertexArray(vaoID[1]); // select second VAO glVertexAttrib3f(1, 1.0, 0.0, 0.0); // set constant color attribute glDrawArrays(GL_TRIANGLES, 0, 3); // draw second object
glBindVertexArray(0);
//glslsimpleprog.Disable; //back to fixed pipeline
glXSwapBuffers(Display, Window); //swaps buffers move to where glDraw is called ... end;
begin writeln ('Hello World'); //see if opengl is available and activate it if InitOpenGL = false then writeln ('No OpenGL support on your system'); writeln ('We may have opengl support');
//set up a xwindow Display := XOpenDisplay(nil); if not Assigned(Display) then Exit;
writeln ('We may have an display');
Screen := XDefaultScreen(Display); writeln ('We may have an screen');
//set up attributes for opengl context attributes[0] := GLX_USE_GL; attributes[1] := GLX_RGBA; //this needs to be provides or else nothing... attributes[2] := GLX_DOUBLEBUFFER; attributes[3] := GLX_RED_SIZE; attributes[4] := 8; attributes[5] := GLX_GREEN_SIZE; attributes[6] := 8; attributes[7] := GLX_BLUE_SIZE; attributes[8] := 8; attributes[9] := GLX_DEPTH_SIZE; attributes[10] := 24; attributes[11] := none; attributes[12] := 0; VisualInfo := glXChooseVisual(Display, Screen, @attributes[0]); if (VisualInfo=nil) then Exit;
writeln ('We may have visual info');
oglcontext := glXCreateContext(Display, VisualInfo, nil, true); writeln ('We may have an context');
//actualy make the window Window := XCreateSimpleWindow(Display, XRootWindow(Display, Screen), 100, 100, 300, 200, 3, 0, 256*256*256-1); //white writeln ('We may have an visible window');
//what kind of input is used for the window //that is mouse, mousebuttons and checking if the window is overlapped XSelectInput (Display, Window, ButtonPressMask or ExposureMask or PointerMotionMask); //make an canvas for the window Canvas := XCreateGC(Display, Window, 0, @CanvasValues);
//make the window visible XMapWindow(Display, Window); writeln ('We may have an realy visible display');
//make the opengl context visible glXMakeCurrent(Display, Window, oglcontext); writeln ('We may have an visible opengl context');
// Read And Assign Extentions ReadExtensions; ReadImplementationProperties; writeln ('We may have calleable opengl commands ...');
//execute your opengl init code glinit();
//main application loop while (true) do begin writeln ('loop'); XNextEvent(Display, @Event); case Event._type of Expose: gldraw(); //draw your opengl scene when exposed ButtonPressMask: break; //onc mouseclick exit application //MotionNotify: XDrawPoint(Display, Window, Canvas, // Event.xmotion.x, Event.xmotion.y); end; //gldraw(); //draw your opengl scene every frame end;
//clean up when closing xwindow glXMakeCurrent(display, 0, 0); glXDestroyContext(Display, oglcontext);
Mitglieder in diesem Forum: Bing [Bot] und 12 Gäste
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.