Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
DLL functions not calling properly
Topic Started: Apr 27 2007, 07:42 AM (367 Views)
qwertyuiop23
Member
[ *  * ]
I am making a DLL using GLFW, this is an OpenGL library. I have ported it so far so that it can display a white triangle with no iput from the user. It simply calls the dll sending out varaibles which if set up that function uses those varaibles to do things. Now here is my problem. I can't get variables into a function then into another that draws them. Here is my source code:

Code:
 
#include <stdlib.h>    // For malloc() etc.
#include <stdio.h>     // For printf(), fopen() etc.
#include <math.h>      // For sin(), cos() etc.
#include <GL/glfw.h>   // For GLFW, OpenGL and GLU
#define dll extern "C" __declspec(dllexport) double __cdecl

dll draw_triangle(double x1)//FUNCTION I"M TRYING TO PUT IN
{
   glBegin( GL_TRIANGLES );          // Tell OpenGL that we want to draw a triangle
   glVertex3f( x1, -4, 0 ); // First corner of the triangle
   glVertex3f(  5, -4, 0 ); // Second corner of the triangle
   glVertex3f(  0,  4, 0 ); // Third corner of the triangle
   glEnd();
}  


dll Draw()
{
   int    width, height;  // Window dimensions
   double t;              // Time (in seconds)
   GLuint TexID;

   // Get current time
   t = glfwGetTime();

   // Get window size
   glfwGetWindowSize( &width, &height );

   // Make sure that height is non-zero to avoid division by zero
   height = height < 1 ? 1 : height;

   // Set viewport
   glViewport( 0, 0, width, height );

   // Clear color and depht buffers
   glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

   // Set up projection matrix
   glMatrixMode( GL_PROJECTION );    // Select projection matrix
   glLoadIdentity();                 // Start with an identity matrix
   gluPerspective(                   // Set perspective view
       65.0,                         // Field of view = 65 degrees
       (double)width/(double)height, // Window aspect (assumes square pixels)
       1.0,                          // Near Z clipping plane
       100.0                         // Far Z clippling plane
   );

   // Set up modelview matrix
   glMatrixMode( GL_MODELVIEW );     // Select modelview matrix
   glLoadIdentity();                 // Start with an identity matrix
   gluLookAt(                        // Set camera position and orientation
       0.0, 0.0, 10.0,               // Camera position (x,y,z)
       0.0, 0.0, 0.0,                // View point (x,y,z)
       0.0, 1.0, 0.0                 // Up-vector (x,y,z)
   );

   glBegin( GL_TRIANGLES );          // Tell OpenGL that we want to draw a triangle
   draw_triangle() //PROBLEM HERE
   glEnd();  
                 // No more triangles...
}


//----------------------------------------------------------------------
// main() - Program entry point
//----------------------------------------------------------------------

dll Engine_start()
{
   int    ok;             // Flag telling if the window was opened
   int    running;        // Flag telling if the program is running

   // Initialize GLFW
   glfwInit();

   // Open window
   ok = glfwOpenWindow(
       640, 480,          // Width and height of window
       8, 8, 8,           // Number of red, green, and blue bits for color buffer
       8,                 // Number of bits for alpha buffer
       24,                // Number of bits for depth buffer (Z-buffer)
       0,                 // Number of bits for stencil buffer
       GLFW_WINDOW        // We want a desktop window (could be GLFW_FULLSCREEN)
   );

   // If we could not open a window, exit now
   if( !ok )
   {
       glfwTerminate();
       return 0;
   }

   // Set window title
   glfwSetWindowTitle( "My OpenGL program" );

   // Enable sticky keys
   glfwEnable( GLFW_STICKY_KEYS );

   // Main rendering loop
   do
   {
       // Call our rendering function
       Draw();

       // Swap front and back buffers (we use a double buffered display)
       glfwSwapBuffers();

       // Check if the escape key was pressed, or if the window was closed
       running = !glfwGetKey( GLFW_KEY_ESC ) &&
                 glfwGetWindowParam( GLFW_OPENED );
   }
   while( running );

   // Terminate GLFW
   glfwTerminate();

   // Exit program
   return 0;
}

This solution won't work
Quote:
 
You have not given draw_triangle() any parameters ..

your draw_triangles(double x1) .. takes 1 parameter (x1) right ??

so here in your draw() function
Code:
 
glBegin( GL_TRIANGLES );          //NOT REQUIRED
   draw_triangle(1.0f) //ADD VALUE HERE
glEnd();          //NOT REQUIRED
 

As this is a DLL i need to call it and put in the variable x1. SO i call the DLL in my calling program i scall it with values draw_triangle(-5) but using the code you supplied no matter what value you call draw_triangle() with it always sets it back to one in the draw() function.

My problem is in the draw_triangle function. IN the program i use to call it i put in call it with value -5 so it sets x1 to -5 (it can only handle double). Tehn it shoudl set that code then draw it in the Draw() function (at the end) but it doesn't it says error to few arguments to function draw_triangle(double). How do i do this?


Cheers
Qwertyuiop23

PS:Tell me if you need more info or the GM6 file as well. Oh and it is compiled using Dev C++ and the GLFW + Opengl package from devpaks.org.

I asked here as Dr. Best has already managed to do this so i was wondering how he did it. But if anyone has anyother solutions please post
Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
You can use a global variable for this. Just like this:
Code:
 
#include <stdlib.h>    // For malloc() etc.
#include <stdio.h>     // For printf(), fopen() etc.
#include <math.h>      // For sin(), cos() etc.
#include <GL/glfw.h>   // For GLFW, OpenGL and GLU
#define dll extern "C" __declspec(dllexport) double __cdecl
double GMX1=0.0f;

dll draw_triangle(double x1)//FUNCTION I"M TRYING TO PUT IN
{
  GMX1=x1;
}  


dll Draw()
{
  int    width, height;  // Window dimensions
  double t;              // Time (in seconds)
  GLuint TexID;

  // Get current time
  t = glfwGetTime();

  // Get window size
  glfwGetWindowSize( &width, &height );

  // Make sure that height is non-zero to avoid division by zero
  height = height < 1 ? 1 : height;

  // Set viewport
  glViewport( 0, 0, width, height );

  // Clear color and depht buffers
  glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  // Set up projection matrix
  glMatrixMode( GL_PROJECTION );    // Select projection matrix
  glLoadIdentity();                 // Start with an identity matrix
  gluPerspective(                   // Set perspective view
      65.0,                         // Field of view = 65 degrees
      (double)width/(double)height, // Window aspect (assumes square pixels)
      1.0,                          // Near Z clipping plane
      100.0                         // Far Z clippling plane
  );

  // Set up modelview matrix
  glMatrixMode( GL_MODELVIEW );     // Select modelview matrix
  glLoadIdentity();                 // Start with an identity matrix
  gluLookAt(                        // Set camera position and orientation
      0.0, 0.0, 10.0,               // Camera position (x,y,z)
      0.0, 0.0, 0.0,                // View point (x,y,z)
      0.0, 1.0, 0.0                 // Up-vector (x,y,z)
  );

  glBegin( GL_TRIANGLES );          // Tell OpenGL that we want to draw a triangle
  glVertex3f( GMX1, -4, 0 ); // First corner of the triangle
  glVertex3f(  5, -4, 0 ); // Second corner of the triangle
  glVertex3f(  0,  4, 0 ); // Third corner of the triangle
  draw_triangle() //PROBLEM HERE
  glEnd();  
                // No more triangles...
}

My guess is that your code didn't work, because glBegin(...) resets the stream input. Since I've never worked with OpenGL this is just a guess anyway.
Offline Profile Quote Post Goto Top
 
« Previous Topic · Off-topic · Next Topic »
Add Reply