C program with g2 graphic library

This is a discussion on C program with g2 graphic library within the C Programming forums, part of the General Programming Boards category; Hey, I had to create a graphic with g2 graphic library, but the program doesn't draw anything, not even the ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Location
    Portugal
    Posts
    20

    C program with g2 graphic library

    Hey,
    I had to create a graphic with g2 graphic library, but the program doesn't draw anything, not even the line. Also, I can't change the font size. I'm using gcc with -Wall -ansi -pedantic -lgd -lX11 -lm and -lg2. I have ubuntu running in virtualbox.
    Could you give me some help?
    Here's the code:

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<g2.h>
    #include<g2_X11.h>
    #include<math.h>
    
    
    void funcao1(janela){
    
        const double pi = 4.*atan(1.);
    
        int x;
        float y1;
    
        while(x!=600){
    
    
        y1=sin(2*pi*0.01*x)+300;
        
        g2_pen(janela,2);
    
        g2_plot(janela,x,y1);
        x=x+1;
        
    
        }
    
        return (1);
        }
    
    
    
    
    int main(){
        int janela;
    
        janela = g2_open_X11(800,600);
    
        g2_line(janela,1,300,1,300);
    
        funcao1(janela);
        
        
    
    
        
    
    
    
        getchar();
        g2_close(janela);
        exit(0);
    }
    Also, could someone explain to me why I couldn't put zero in the return? As far as I know, the function won't return anything or will it?
    Last edited by Chinchila; 10-24-2012 at 12:31 PM. Reason: Added question.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    you probably need a g2_flush in there after your drawing commands

    edit: btw I never heard of g2. all I did was google 'g2 graphics library example' and got this link http://www.tp.umu.se/modsim/linux-guide/g2.html
    Last edited by dmh2000; 10-24-2012 at 02:38 PM. Reason: clarification

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    What is the value of x in funcao1 before the loop starts? It's probably not 0.

    Why are you drawing a line between (1,300) and (1,300)? That would be a single point (or no point at all if the line drawing routine does not draw the last pixel of the line).

    Also, you cannot return any value from a function declared as returning void. You can use a return statement without a return value (you also don't need parentheses; return is not a function call). On the other hand, if it's at the end of a void function a return statement is not needed. You should also return 0 from main (though exit(0) has the same effect in practice).

  4. #4
    Registered User
    Join Date
    Oct 2012
    Location
    Portugal
    Posts
    20
    X is supposed to be the beginning of my graphic, as in y=sen(2*pi*1.0*x). What i mean is, I want to start drawing the graph from x=0.
    That's what I tought, but gcc was warning me that the function returns a value.
    Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Graphic Manipulation Library
    By MathewCollins in forum C++ Programming
    Replies: 2
    Last Post: 09-06-2010, 01:57 AM
  2. Shell graphic program
    By publikum in forum Linux Programming
    Replies: 3
    Last Post: 03-08-2005, 11:08 AM
  3. IDEA: A program to make a graphic of any file
    By carrja99 in forum Contests Board
    Replies: 1
    Last Post: 10-21-2002, 12:33 PM
  4. Which graphic library do you prefer?
    By Golden Bunny in forum Game Programming
    Replies: 21
    Last Post: 05-04-2002, 04:29 PM
  5. graphic library creation
    By bob5845 in forum C++ Programming
    Replies: 1
    Last Post: 04-04-2002, 11:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21