Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1464 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  OpenGl dans une fenêtre définie avec visual .Net

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

OpenGl dans une fenêtre définie avec visual .Net

n°1120313
leFab
Itadakimasu !!!
Posté le 15-06-2005 à 09:18:52  profilanswer
 

Bonjour,
 
Je trouve beaucoup d'exemples de l'utilisation d'openGl avec les MFC de visual C++ 6, mais impossible de trouver l'équivalent en visual .NET. Quelqu'un pour m'aider ? Merci.


---------------
L'ennemi est con : il croit que c'est nous l'ennemi, alors que c'est lui ! (Desproges)
mood
Publicité
Posté le 15-06-2005 à 09:18:52  profilanswer
 

n°1120347
zetranber
Posté le 15-06-2005 à 09:52:26  profilanswer
 

Petite aide rapide :
 
Dans ta fenetre :

Code :
  1. /// <summary>
  2.  /// Variable nécessaire au concepteur.
  3.  /// </summary>
  4.  private System.ComponentModel.Container components = null;
  5.  public Paquetage.Composants.myOpenGLControl view;
  6.  public OpenGLForm()
  7.  {
  8.   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  9.   this.ClientSize = new System.Drawing.Size(640, 480);
  10.   this.Name = "MainForm";
  11.   this.Text = "About ...";
  12.   this.view = new Paquetage.Composants.myOpenGLControl();
  13.   this.view.Parent = this;
  14.   this.view.Dock = DockStyle.Fill;
  15.   this.CenterToScreen();
  16.   this.TopMost = true;
  17.   this.Show();
  18.  }


 
Ensuite tout est dans le user control myOpenGLControl.
Exemple pour une caisse qui tourne :

Code :
  1. using System;
  2. using System.ComponentModel;
  3. using System.Collections;
  4. using System.Diagnostics;
  5. using CsGL.OpenGL;
  6. using System.Windows.Forms;
  7. using System.Drawing;
  8. namespace Paquetage.Composants
  9. {
  10. /// <summary>
  11. /// Description résumée de OpenGLControl.
  12. /// </summary>
  13. public class myOpenGLControl : OpenGLControl
  14. {
  15.  /// <summary>
  16.  /// Variable nécessaire au concepteur.
  17.  /// </summary>
  18.  private System.ComponentModel.Container components = null;
  19.  public bool light = true;
  20.  public bool lp = false;
  21.  public bool fp = false;
  22.  public float xrot = 0.0f;
  23.  public float yrot = 0.0f;
  24.  public float zrot = 0.0f;
  25.  public float xspeed = 0.0f;
  26.  public float yspeed = 0.0f;
  27.  public float z = -5.0f;
  28.  // Lighting components for the cube
  29.  public float[] LightAmbient =  {0.5f, 0.5f, 0.5f, 1.0f};
  30.  public float[] LightDiffuse =  {1.0f, 1.0f, 1.0f, 1.0f};
  31.  public float[] LightPosition = {0.0f, 0.0f, 2.0f, 1.0f};
  32.  public int filter = 0;     // Which Filter To Use
  33.  public uint[] texture = new uint[3]; // Texture array
  34.  public bool finished;
  35.  public myOpenGLControl() : base()
  36.  {
  37.   this.KeyDown += new KeyEventHandler(LessonView_KeyDown);
  38.   this.KeyUp += new KeyEventHandler(LessonView_KeyUp);
  39.   this.finished = false;
  40.  }
  41.  protected void OurView_OnKeyDown(object Sender, KeyEventArgs kea)
  42.  {
  43.   //if escape was pressed exit the application
  44.   if (kea.KeyCode == Keys.Escape)
  45.   {
  46.    finished = true;
  47.   }
  48.  }
  49.  public override void glDraw()
  50.  {
  51.   GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  52.   GL.glLoadIdentity();
  53.   GL.glTranslatef(0.0f, 0.0f, this.z);
  54.   GL.glRotatef(this.xrot, 1.0f, 0.0f, 0.0f);
  55.   GL.glRotatef(this.yrot, 0.0f, 1.0f, 0.0f);
  56.   GL.glBindTexture(GL.GL_TEXTURE_2D, this.texture[filter]);
  57.   GL.glBegin(GL.GL_QUADS);
  58.   // Front Face
  59.   GL.glNormal3f( 0.0f, 0.0f, 1.0f);
  60.   GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f,  1.0f);
  61.   GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f,  1.0f);
  62.   GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f,  1.0f);
  63.   GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f,  1.0f);
  64.   // Back Face
  65.   GL.glNormal3f( 0.0f, 0.0f,-1.0f);
  66.   GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f);
  67.   GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f, -1.0f);
  68.   GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f, -1.0f);
  69.   GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f, -1.0f);
  70.   // Top Face
  71.   GL.glNormal3f( 0.0f, 1.0f, 0.0f);
  72.   GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f, -1.0f);
  73.   GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f,  1.0f,  1.0f);
  74.   GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f( 1.0f,  1.0f,  1.0f);
  75.   GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f, -1.0f);
  76.   // Bottom Face
  77.   GL.glNormal3f( 0.0f,-1.0f, 0.0f);
  78.   GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f);
  79.   GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f( 1.0f, -1.0f, -1.0f);
  80.   GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f,  1.0f);
  81.   GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f,  1.0f);
  82.   // Right face
  83.   GL.glNormal3f( 1.0f, 0.0f, 0.0f);
  84.   GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f, -1.0f);
  85.   GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f, -1.0f);
  86.   GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f,  1.0f);
  87.   GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f,  1.0f);
  88.   // Left Face
  89.   GL.glNormal3f(-1.0f, 0.0f, 0.0f);
  90.   GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f);
  91.   GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f,  1.0f);
  92.   GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f,  1.0f);
  93.   GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f, -1.0f);
  94.   GL.glEnd();
  95.   this.xrot += this.xspeed;
  96.   this.yrot += this.yspeed;
  97.  }
  98.  protected override void InitGLContext()
  99.  {
  100.   LoadTextures();
  101.   GL.glEnable(GL.GL_TEXTURE_2D);         // Enable Texture Mapping
  102.   GL.glShadeModel(GL.GL_SMOOTH);         // Enable Smooth Shading
  103.   GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);      // Black Background
  104.   GL.glClearDepth(1.0f);           // Depth Buffer Setup
  105.   GL.glEnable(GL.GL_DEPTH_TEST);         // Enables Depth Testing
  106.   GL.glDepthFunc(GL.GL_LEQUAL);         // The Type Of Depth Testing To Do
  107.   GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);  // Really Nice Perspective Calculations
  108.   GL.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT,  this.LightAmbient); // Setup The Ambient Light
  109.   GL.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE,  this.LightDiffuse); // Setup The Diffuse Light
  110.   GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, this.LightPosition); // Position The Light
  111.   GL.glEnable(GL.GL_LIGHT1);          // Enable Light One
  112.   if (this.light)             // If lighting, enable it to start
  113.    GL.glEnable(GL.GL_LIGHTING);
  114.  }
  115.  protected bool LoadTextures()
  116.  {
  117.   Bitmap image = null;
  118.   string file = @"Crate.bmp";
  119.   try
  120.   {
  121.    // If the file doesn't exist or can't be found, an ArgumentException is thrown instead of
  122.    // just returning null
  123.    image = new Bitmap(file);
  124.   }
  125.   catch (System.ArgumentException)
  126.   {
  127.    MessageBox.Show("Could not load " + file + ".  Please make sure that Data is a subfolder from where the application is running.", "Error", MessageBoxButtons.OK);
  128.    this.finished = true;
  129.   }
  130.   if (image != null)
  131.   {
  132.    image.RotateFlip(RotateFlipType.RotateNoneFlipY);
  133.    System.Drawing.Imaging.BitmapData bitmapdata;
  134.    Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
  135.    bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  136.    GL.glGenTextures(3, this.texture);
  137.    // Create Nearest Filtered Texture
  138.    GL.glBindTexture(GL.GL_TEXTURE_2D, this.texture[0]);
  139.    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
  140.    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
  141.    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
  142.    // Create Linear Filtered Texture
  143.    GL.glBindTexture(GL.GL_TEXTURE_2D, this.texture[1]);
  144.    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
  145.    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
  146.    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
  147.    // Create MipMapped Texture
  148.    GL.glBindTexture(GL.GL_TEXTURE_2D, this.texture[2]);
  149.    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
  150.    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_NEAREST);
  151.    GL.gluBuild2DMipmaps(GL.GL_TEXTURE_2D, (int)GL.GL_RGB, image.Width, image.Height, GL.GL_BGR_EXT, GL.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
  152.    image.UnlockBits(bitmapdata);
  153.    image.Dispose();
  154.    return true;
  155.   }
  156.   return false;
  157.  }
  158.  protected override void OnSizeChanged(EventArgs e)
  159.  {
  160.   base.OnSizeChanged(e);
  161.   Size s = Size;
  162.   if (s.Height == 0)
  163.    s.Height = 1;
  164.   GL.glViewport(0, 0, s.Width, s.Height);
  165.   GL.glMatrixMode(GL.GL_PROJECTION);
  166.   GL.glLoadIdentity();
  167.   GL.gluPerspective(45.0f, (double)s.Width /(double) s.Height, 0.1f, 100.0f);
  168.   GL.glMatrixMode(GL.GL_MODELVIEW);
  169.   GL.glLoadIdentity();
  170.  }
  171.  protected void LessonView_KeyDown(object Sender, KeyEventArgs e)
  172.  {
  173.   if (e.KeyCode == Keys.Escape)    // Finish the application if the escape key was pressed
  174.    this.finished = true;
  175.   else if (e.KeyCode == Keys.L && !this.lp) // On the L key, flip the lighting mode
  176.   {
  177.    this.lp = true;
  178.    this.light = !this.light;
  179.    if (this.light)
  180.     GL.glEnable(GL.GL_LIGHTING);
  181.    else
  182.     GL.glDisable(GL.GL_LIGHTING);
  183.   }
  184.   else if (e.KeyCode == Keys.F && !this.fp) // On the F key, cycle the texture filter (texture used)
  185.   {
  186.    this.fp = true;
  187.    this.filter = (filter + 1) % 3;
  188.   }
  189.   else if (e.KeyCode == Keys.PageUp)   // On page up, move out
  190.    this.z -= 0.02f;
  191.   else if (e.KeyCode == Keys.PageDown)  // On page down, move in
  192.    this.z += 0.02f;
  193.  }
  194.  private void LessonView_KeyUp(object sender, KeyEventArgs e)
  195.  {
  196.   if (e.KeyCode == Keys.L)     // Release the lighting toggle key lock
  197.    this.lp = false;
  198.   else if (e.KeyCode == Keys.F)    // Release the filter cycle key lock
  199.    this.fp = false;
  200.  }
  201.  protected override bool ProcessDialogKey(Keys keyData)
  202.  {
  203.   if (keyData == Keys.Up)      // Change rotation about the x axis
  204.    this.xspeed -= 0.01f;
  205.   else if (keyData == Keys.Down)
  206.    this.xspeed += 0.01f;
  207.   else if (keyData == Keys.Right)    // Change rotation about the y axis
  208.    this.yspeed += 0.01f;
  209.   else if (keyData == Keys.Left)
  210.    this.yspeed -= 0.01f;
  211.   return base.ProcessDialogKey (keyData);
  212.  }
  213.  /// <summary>  
  214.  /// Nettoyage des ressources utilisées.
  215.  /// </summary>
  216.  protected override void Dispose( bool disposing )
  217.  {
  218.   if( disposing )
  219.   {
  220.    if(components != null)
  221.    {
  222.     components.Dispose();
  223.    }
  224.   }
  225.   base.Dispose( disposing );
  226.  }
  227.  #region Code généré par le Concepteur de composants
  228.  /// <summary>
  229.  /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
  230.  /// le contenu de cette méthode avec l'éditeur de code.
  231.  /// </summary>
  232.  private void InitializeComponent()
  233.  {
  234.   components = new System.ComponentModel.Container();
  235.  }
  236.  #endregion
  237. }
  238. }


 

n°1120392
leFab
Itadakimasu !!!
Posté le 15-06-2005 à 10:25:57  profilanswer
 

Whaaa !  :love:  
 
Merci beaucoup  :jap:


---------------
L'ennemi est con : il croit que c'est nous l'ennemi, alors que c'est lui ! (Desproges)
n°1120464
leFab
Itadakimasu !!!
Posté le 15-06-2005 à 10:49:10  profilanswer
 

Sinon, j'ai déjà une IHM dessinée, et ce que je voudrais faire exactement, c'est utiliser dans un Window Form "Panel", un code openGl déjà écrit avec la glut.  
 
C'est simple ?


Message édité par leFab le 15-06-2005 à 10:49:34

---------------
L'ennemi est con : il croit que c'est nous l'ennemi, alors que c'est lui ! (Desproges)
n°1120516
zetranber
Posté le 15-06-2005 à 11:11:48  profilanswer
 

Et bien si tu intègre ton user control dans le panel au lieu de la form, ca devrait marcher de la même manière :)

n°1120713
gedeon
Posté le 15-06-2005 à 13:13:28  profilanswer
 

Au passage Visual .Net n'existe pas, et ça ne veut rien dire
Si tu voulais dire Framework .net, il te rester a preciser le langage --> C#. Sinon il fallait dire Visual Studio .Net  en C#. Je sais je suis tatillon. Mais  sachant que Visual C++ .net existe .... et que tu parlais de Visual C++ 6,  on aurais put croire que tu voulais du C++.

n°1120721
leFab
Itadakimasu !!!
Posté le 15-06-2005 à 13:19:56  profilanswer
 

A vrai dire, j'en sais trop rien. C'est du Visual C++, et j'ai créé une "application visual forms (.NET)". Et c'est tout bizarre, je pleure par rapport aux anciens MFC...
 
Et au passage, "Visual Studio .NET" est un terme qui est utilisé sur le site msdn de crosoft.


Message édité par leFab le 15-06-2005 à 13:23:25

---------------
L'ennemi est con : il croit que c'est nous l'ennemi, alors que c'est lui ! (Desproges)
n°1120814
gedeon
Posté le 15-06-2005 à 14:27:14  profilanswer
 

leFab a écrit :

A vrai dire, j'en sais trop rien. C'est du Visual C++, et j'ai créé une "application visual forms (.NET)". Et c'est tout bizarre, je pleure par rapport aux anciens MFC...


 
C'est donc du C++ utilisant les bibliotheque .Net.
Mélange de code managé et non managé. Tu prend pas le chemin le plus facile.
Le code fourni dans le topic est du C# !
 

leFab a écrit :


Et au passage, "Visual Studio .NET" est un terme qui est utilisé sur le site msdn de crosoft.


 
Je suis d'accord avec toi mais toi tu as utilisé Visual .Net ;)  
Et de toute facon Visual Studio .Net ne defini pas le langage mais l'environement dev qui comprend le C#, le VB.net, le C++ et le J#
 
Tu aurais du faire un projet  "Application MFC" pour t'y retrouver


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  OpenGl dans une fenêtre définie avec visual .Net

 

Sujets relatifs
[Visual C++/MFC] Redimensionnementouvrir une page dans une autre fenêtre du navigateur
[ACCESS] fenetre intempestive formulaire[OpenGL] Problème de tache spéculaire
[VB.Net] Click droit dans l'explorateur[MFC][URGENT]Afficher une fenetre fille en premier plan
[Visual C++]TemplateRaffraichissment de la fenetre appelante via un Pop Up?
Visual Studio .NET pro & entreprise 
Plus de sujets relatifs à : OpenGl dans une fenêtre définie avec visual .Net


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR