Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jul 15, 2025 14:44

Foren-Übersicht » Programmierung » Allgemein
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: XCreateWindow und OpenGL
BeitragVerfasst: Do Nov 18, 2010 21:41 
Offline
DGL Member
Benutzeravatar

Registriert: Di Dez 03, 2002 22:12
Beiträge: 2105
Wohnort: Vancouver, Canada
Programmiersprache: C++, Python
Hi,

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?

Aya~


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: XCreateWindow und OpenGL
BeitragVerfasst: Do Nov 18, 2010 22:52 
Offline
DGL Member
Benutzeravatar

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 }
{******************************************************************************}

program minimalxapp;

uses
  X, XLib, XUtil, keysym, classes, sysutils, dglOpenGL, DglShader;

var
 Display: PDisplay;
 Window: TWindow;
 Screen: Integer;
 Event: TXEvent;
 Canvas: TGC;
 CanvasValues: TXGCValues;
 VisualInfo: PXVisualInfo;
 oglcontext: GLXContext;
 attributes: array [0..40] of integer;

  //shaders
  glslsimplevert: TGLSLShader;
  glslsimplefrag: TGLSLShader;
  glslsimpleprog: TGLSLProgram;

  //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;


{------------------------------------------------------------------}
{  Initialise OpenGL                                               }
{------------------------------------------------------------------}
procedure glInit();
var
  ln: integer;
  x: integer;
  y: integer;
  theta: GLFloat;
  phi: GLFloat;
  r: GLFloat;
  vert: array[0..8] of GLFloat;   //vertex array #1
  vert2: array[0..8] of GLFloat;  //Vertex array #2
  col: array[0..8] of GLFloat;    //Color array #1
begin
  //load simple glsl shader
  glslsimpleprog := TGLSLProgram.Create();
  glslsimplevert := TGLSLShader.Create('/home/marten/pascal/opengl/minx/Shaders/minimal.vert');
  glslsimplefrag := TGLSLShader.Create('/home/marten/pascal/opengl/minx/Shaders/minimal.frag', GL_FRAGMENT_SHADER_ARB);
  glslsimpleprog.Attach(glslsimplevert);
writeln(glslsimplevert.log);

  glslsimpleprog.Attach(glslsimplefrag);
writeln(glslsimplefrag.log);

  //glslsimpleprog.BindAttribLocation('in_Position',0);
  //glslsimpleprog.BindAttribLocation('in_Color',1);

  glslsimpleprog.Link;

writeln(glslsimpleprog.log);

  // Create VAO's en VBO's and fill them with data

  // First simple object
  vert[0] :=-0.3; vert[1] := 0.5; vert[2] :=-1.0;
   vert[3] :=-0.8; vert[4] :=-0.5; vert[5] :=-1.0;
   vert[6] := 0.2; vert[7] :=-0.5; vert[8] :=-1.0;

   col[0] := 1.0; col[1] := 0.0; col[2] := 0.0;
   col[3] := 0.0; col[4] := 1.0; col[5] := 0.0;
   col[6] := 0.0; col[7] := 0.0; col[8] := 1.0;

   // Second simple object
   vert2[0] :=-0.2; vert2[1] := 0.5; vert2[2] :=-1.0;
   vert2[3] := 0.3; vert2[4] :=-0.5; vert2[5] :=-1.0;
   vert2[6] := 0.8; vert2[7] := 0.5; vert2[8] :=-1.0;

  // Two VAO allocation's
  glGenVertexArrays(2,@vaoID);

  // First VAO setup
  glBindVertexArray(vaoID[0]);

  glGenBuffers(2, @vboID);

  glBindBuffer(GL_ARRAY_BUFFER, vboID[0]);
  glBufferData(GL_ARRAY_BUFFER,9*sizeof(GLFloat), @vert, GL_STATIC_DRAW);
  glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
   glEnableVertexAttribArray(0);

   glBindBuffer(GL_ARRAY_BUFFER, vboID[1]);
   glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLFloat), @col, GL_STATIC_DRAW);
   glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0);
   glEnableVertexAttribArray(1);

   // Second VAO setup
   glBindVertexArray(vaoID[1]);

   glGenBuffers(1, @vboID);

   glBindBuffer(GL_ARRAY_BUFFER, vboID[0]);
   glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLfloat), @vert2, GL_STATIC_DRAW);
   glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
   glEnableVertexAttribArray(0);

   glBindVertexArray(0);

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);

 XDestroyWindow(Display, Window);
 XCloseDisplay(Display);

end.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: XCreateWindow und OpenGL
BeitragVerfasst: Fr Nov 19, 2010 23:06 
Offline
DGL Member
Benutzeravatar

Registriert: Di Dez 03, 2002 22:12
Beiträge: 2105
Wohnort: Vancouver, Canada
Programmiersprache: C++, Python
Thanks,

was a big help :)


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Foren-Übersicht » Programmierung » Allgemein


Wer ist online?

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.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.008s | 15 Queries | GZIP : On ]