Jump to content
  • Advertisement
Sign in to follow this  
qwertyuiop23

OpenGL Making a DLL

This topic is 4078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a DLL using GLFW. I have converted it so far so that it can dsiplay a white triangle with no iput from the user. To run the DLL i am using a program called GameMaker 7.0. 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:
#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;
}

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.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Well the error is your problem !!

You have not given draw_triangle() any parameters ..

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

so here in your draw() function

glBegin( GL_TRIANGLES ); //NOT REQUIRED
draw_triangle(5) //ADD VALUE HERE
glEnd(); //NOT REQUIRED








Also note glBegin( GL_TRIANGLES) (and glEnd) are not required, as it's the first/last thing you do in your draw_triangle() function..

[wink]

[Edited by - darren_mfuk on April 24, 2007 5:31:17 AM]

Share this post


Link to post
Share on other sites
Thanks thats partly solved my question. BUT 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.

Cheers
Qwertyuiop23

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!